-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Newbie Question - IN Clause
PostPosted: Fri Jan 29, 2010 5:48 pm 
Newbie

Joined: Fri Jan 29, 2010 5:31 pm
Posts: 1
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.