我不明白为什么这个查询没有给我任何结果。我知道数据存在于表中。results
执行查询时,列表变量“ ”为空。我是否正确实现了复合键?
我什至尝试使用@EmbeddedId
来完成此操作,但返回的列表仍然是空的。
Session sess = HibernateUtil.getSession();
Criteria criteria = sess.createCriteria(Employee.class);
criteria.add(Restrictions.eq("employeeId", 255847208));
criteria.add(Restrictions.eq("serialId", 461));
List<Employee> results = criteria.list();
主键类
public class EmpPrmryKey implements Serializable {
private Integer employeeId;
private Integer serialId;
//getters and setters
}
POJO 映射到表:
@Entity
@IdClass(EmpPrmryKey.class)
@Table(name = "EMPLOYEE")
public class Employee{
private EmpPrmryKey compositeId;
@Id
@Column(name = "employee_id")
private Integer employeeId;
@Id
@Column(name = "serial_id")
private Integer serialId;
//getters and setters
}