【发布时间】:2021-02-10 05:14:10
【问题描述】:
感谢我的 DTO 类,我希望检索数据库中包含的信息。 问题是,如果我不理解原因,我的查询就无法工作......
来自数据库的实体
@Entity
@Table(name = "historiquedeploiement")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HistoriqueDeploiement {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "idnamespace", nullable = false)
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
@JsonIdentityReference(alwaysAsId=true)
@JsonProperty("idnamespace")
private Namespace namespace;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "idservice", nullable = false)
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
@JsonIdentityReference(alwaysAsId=true)
@JsonProperty("idservice")
private Service service;
@NotEmpty
@Size(max = 100)
private String tagvalue;
}
DTO:
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HistoriqueDeploiementReadingDTO {
private Integer id;
@NotEmpty
private String namespacename;
@NotEmpty
private String servicename;
@NotEmpty
private String tagvalue;
}
我的查询:
@Repository
public interface HistoriqueDeploiementRepository extends JpaRepository<HistoriqueDeploiement, Integer> {
List<HistoriqueDeploiement> findAll();
// Problem Here
Error creating bean with name 'historiqueDeploiementRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.example.jpa.repository.HistoriqueDeploiementRepository.findAllDeploiement()!
@Query("SELECT new com.example.jpa.dto.HistoriqueDeploiementReadingDTO(historiquedeploiement.id, namespace.namespacename, service.servicename, historiquedeploiement.tagvalue) FROM historiquedeploiement, namespace, service WHERE namespace.id = historiquedeploiement.idnamespace and service.id = historiquedeploiement.idservice")
List<HistoriqueDeploiementReadingDTO> findAllDeploiement();
}
我的目标是让这个查询正常工作:)
如果你认为你有比解决这个问题更好的主意,请告诉我! 谢谢
【问题讨论】:
-
这能回答你的问题吗? Validation failed for query for method JPQL
-
@RobertBain 我想使用新的运算符。我觉得有可能
-
当您提供错误消息时,人们可以更好地帮助您。例如,Diego Pinto 发布了一个非常好的答案,如果您提供了错误,该答案可能会被保存。
-
从一开始就提供了错误。在“我的查询块”中:// 问题在这里
标签: java sql spring-boot jpa spring-data-jpa