如何使用休眠标准方法让所有员工命名为“John Smith”?
@Entity
public class Name{
private long id;
private String title
private String first;
private String last;
private String suffix;
@OneToMany(mappedby = "name")
private Set<Employee> employees;
}
@Entity
public class Employee{
private long id;
private int age;
private Date dateStarted;
private String highestEducationCompleted;
@ManyToOne
private Name name;
}
我尝试了以下内容并在子查询处理中获得了NullPointerException
。似乎hibernate引擎需要投影子查询,这可能导致这种方法不适用于这个用例:
DetachedCriteria getNames = new DetachedCriteria(Name.class);
getNames.add(Restrictions.and(Restrictions.eq("first", "John"), Restrictions.eq("last", "Smith")));
Criteria getEmployees = getSession().createCriteria(Employee.class);
getEmployees.add(Subqueries.propertyIn("names", getNames);
getEmployees.list();
使用hibernate标准完成此操作的更好方法是什么?
答案 0 :(得分:1)
至少从2005年开始,Hibernate人就已经知道了这个问题并且在很大程度上忽略了它。请在此处查看原始错误报告:https://hibernate.atlassian.net/browse/HHH-993