I cannot understand why this query does not give me any result. I know that data exists in a table. The variable " results" is empty when the request is executed. Am I implementing the composite key correctly?
I even tried using @EmbeddedIdto do this, but the returned list is still empty.
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();
Primary Key Class
public class EmpPrmryKey implements Serializable {
private Integer employeeId;
private Integer serialId;
}
POJO mapped to table:
@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;
}
Susie source
share