【发布时间】:2020-08-07 10:49:08
【问题描述】:
我正在尝试写这个来获取列表,我必须将 ID 列表作为参数传递:
@Query(value = "SELECT OutbreakDiagnosticTests FROM OutbreakDiagnosticTests WHERE OutbreakDiagnosticTests.outbreaks in (:outbreakIds) ")
List<OutbreakDiagnosticTests> getDiagnosticTestsByOutbreaks(@Param("outbreakIds") List<Long> outbreakIds);
我的实体是这个,我用来查询的是这个:
@Entity
@EntityListeners(OutbreakDiagnosticTestManagerImpl.class)
@Table(name = "outbreak_diagnostic_tests")
public class OutbreakDiagnosticTests extends AbstractTemporalWorkingData implements Serializable{
/**
*
*/
private static final long serialVersionUID = 636298998880960358L;
@Id
@Column(nullable = false, name = "obdt_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long obdtId;
@Column(nullable = false, name = "nature", length = 255)
private String nature;
@Column(nullable = true, name = "diagnostic_test_req", length = 255)
private String diagnosticTestReq;
@OneToMany(mappedBy = "outbreakDiagnosticTests", cascade = CascadeType.ALL, orphanRemoval = true)
@Filter(name = "workingData")
private Set<TestsResults> testsResults;
@ManyToOne
@JoinColumn(name = "outbreak_id", nullable = false)
private Outbreaks outbreaks;
@ManyToOne
@JoinColumn(name = "diag_test_id", nullable = true)
private DiagnosticTests diagTests;
@ManyToOne
@JoinColumn(name = "lab_id", nullable = true)
private Laboratories lab;
@Column(nullable = false, name = "is_field")
private Boolean isField = false;
但是运行后我得到了这个异常:
Error creating bean with name 'labTestSummariesDaoImpl': Unsatisfied dependency expressed through field 'obDiagTestRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'outbreakDiagnosticTestRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.wahisplus.wcommon.repository.outbreak.OutbreakDiagnosticTestRepository.getDiagnosticTestsByOutbreaks(java.util.List)!
有人可以帮助我使用上述方法获取列表,或者可以告诉我我在这方面做错了什么。我不想使用本机即(nativeQuery = true)使用它。
【问题讨论】:
标签: spring-boot hibernate jpa spring-data-jpa