我有一个AppUser
类;
class AppUser {
private String firstName;
private String lastName;
//-- getters and setters
}
我也有另一个类
Student
;class Student {
private AppUser appUser;
private Date dateOfBirth;
//-- getters and setters
}
我将如何搜索Student
John Doe
,firstName John,lastName Doe?如果是出生日期属性,我将创建一个
Criteria
并在该日期上添加一个相等限制(Restristions.eq
)。我将如何对AppUser对象中的lastName和firstName进行操作? 最佳答案
询问:
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");
要使用条件,请检查this thread
也看看this page from hibernate docs