我創建了以下類,即教師和學生。過濾器無法處理一對多關係的JPQL查詢
Java代碼:學生
@Entity
@Table(name="Student")
public class Student {
@Id
@Column(name = "cmp_id")
private String cmpId;
@OneToOne(cascade = CascadeType.REFRESH)
@JoinColumn(name = "teacherid", referencedColumnName = "teacherid")
private Teacher teacher;
@OneToOne
@JoinColumn(name = "typeid", referencedColumnName = "typeid")
private Type type;
}
Java代碼:教師
@Entity
@Table(name="Teacher")
public class Teacher {
@Id
@Column(name = "teacherid")
private String teacherid;
@Column(name = "teachername")
private String teachername;
@OneToMany(mappedBy = "Teacher", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@OrderBy("cmpSequence ASC")
private List<Student> std;
}
Java代碼:類型
@Entity
@Table(name="Type")
public class Type{
@Id
@Column(name = "typeid")
private Integer typeid;
@Column(name = "uitype")
private String uitype;
}
教師是父類和學生是孩子class.I希望所有教師和他們的學生與過濾typeid是1,但它不起作用。
以下是JPQL查詢,我創建了:
SELECT teacher FROM Teacher teacher WHERE teacher.std.typeid = 1
它給了我以下錯誤:
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Problem compiling query.The state field path 'teacher.std.typeid' cannot be resolved to a valid type.
的可能的複製[JPQL:狀態字段路徑不能解析爲一個有效的類型(https://stackoverflow.com/questions/20056847/jpql-the-state -field-path-can-be-resolved-to-a-valid-type) – Nikolas
,因爲你的JPQL是無稽之談。您不能在WHERE子句中通過它們引用多值字段,您必須執行顯式JOIN。但是,然後任何基本的JPA文檔將包括這 – DN1