我有兩個類,然後我有一對多的關係。這些類:使用HQL從具有一對多關係的連接表中選擇
@Entity
@Table(name = "emp300", uniqueConstraints = @UniqueConstraint(columnNames = {"personId", "empName","last_name"}))
public class Employee implements Serializable{
@SequenceGenerator(name="seq",sequenceName="my_seq")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq")
@Id
private int Pid;
private String empName, last_name, position, boss,personId;
private String birthDate;
private int salary;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "depId", nullable = false)
private Department department;
//setters and getters
}
和第二個:
@Entity
@Table(name = "dep300", uniqueConstraints = @UniqueConstraint(columnNames = "depName"))
public class Department implements Serializable, Comparable<Department> {
@SequenceGenerator(name = "seq", sequenceName = "DEPARTMENTS_SEQ")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
@Id
private int depId;
private String depName;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "department", cascade=CascadeType.ALL)
private Set<Employee> lst = new HashSet<Employee>(0);
//setters and getters
}
現在我很感興趣,我怎樣才能白色HQL命令得到全體員工的字段中的每個部門(參數傳遞部門名稱)
例外。 hibernate.hql.QueryExecutionRequestException:不支持select查詢[來自ge.ufc.hibernate.Emps.Employee e其中e.department.depName =:mname] – Gog1nA
試試這個,它應該在參數和等號之間有一個空格這個: from Employee e where e.department.depName =:mname; 或者您應該在查詢中修復特定的部門名稱,以確保傳遞參數沒有問題。 –