我有一堂课AppUser;
AppUser
class AppUser { private String firstName; private String lastName; //-- getters and setters }
我还有一节课Student;
Student
class Student { private AppUser appUser; private Date dateOfBirth; //-- getters and setters }
我将如何搜索Student John Doe,名字John,lastName Doe?
John Doe
如果是出生日期属性,我将在日期上创建一个Criteria并添加一个相等限制(Restristions.eq)。我将如何对AppUser对象中的lastName和firstName进行操作?
Criteria
Restristions.eq
查询:
Query q = session.createQuery( "SELECT s from Student s WHERE s.appUser.firstName=:firstName AND s.appUser.lastName=:lastName"); q.setParameter("firstName", "John"); q.setParameter("lastName", "Doe");
要使用条件,请检查此线程
还可以从hibernate文档中查看此页面