Adding more than one class in hibernate criteria
I have the below code
ArrayList<String> city = 'Anniston';
Criteria crit = session.createCriteria(CandidateResumeInfo.class);
crit.add(Restrictions.eq("resumeSearchable", 1));
Now i want to add below criteria
crit.add(Restrictions.in("cities", city));
but the problem is that cities column is not in Cand开发者_运维知识库idateResumeInfo.class its in CandidateInfo Class.
Any idea how to add this criteria as well in the above one,how to add CandidateInfo class as well in the above criteria.
guess i need to do join or link these two tables but how ,and will there be any changes in the entity classes ?
thanks
You didn't describe your associations but I assume it would be something like
class CandidateResumeInfo {
@OneToOne
CandidateInfo candidate;
}
In this case you would need something like
ses.createCriteria(CandidateResumeInfo.class)
.add(Restrictions.eq(...))
.addCriteria('candidate')
.add(Restrictions.in('cities',city);
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querycriteria.html
check section about associations.
精彩评论