I am a newbie to Hibernate, so I hope everyone bears with me on this question.
I have gone through the basics and think I understand most of what I am doing, but I am completely confused on certain WHERE conditions -- namely the in-clause representation.
For example (very loose example), I have the following ad-hoc query for an application which only requires selects to be done:
Code:
select username from users where username in (select dbname from reference)
From what I can figure out, I think the HQL for this would be the following:
Code:
List refs = session.createCritera(Reference.class)
.setProjection(Projections.property("DBNAME"))
.list();
List users = session.createCriteria(Users.class)
.setProjection(Projections.property("PROGRAM"))
.add(Restrictions.in("USERNAME",refs)
.list();
Is this right?
I am trying to understand the "right" way to do this. I know this can probably be done with a createQuery, but it would defeat the whole object relational framework. I really want to understand how to do this correctly.
Also, in my example, the username field is not primary key, but it is a uniquely identified field that is joinable. Does my hbm.xml file have to reflect the relationship on this field in the Users.hbm.xml and Reference.hbm.xml? If so, how do I set that up correctly or is that only if I am concerned with insert, delete, and update?