-->
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.  [ 3 posts ] 
Author Message
 Post subject: IN clause in session.find()
PostPosted: Wed Dec 10, 2003 5:45 am 
Newbie

Joined: Sun Oct 26, 2003 4:46 pm
Posts: 16
Location: Tallinn, Estonia
hello,

I want to run this kind of query:

from X x where x.y in (?)

I found examples of this using session.createQuery() but none using session.find() directly.
Is it possible at all? If it is, what should I specify as the type of the parameter?

I am using Hibernate 2.0.3.

best regards,
erik


Top
 Profile  
 
 Post subject: Re: IN clause in session.find()
PostPosted: Wed Dec 10, 2003 8:42 am 
Newbie

Joined: Tue Nov 18, 2003 9:20 am
Posts: 5
Location: Munich/Germany
hello erik,
IN is supported by hql. Take a look in documentaion at chaper 10 HQL. There are also some examples...

I didn't tried that, but IMO think this should work:

List moreCats = sess.find(
"from Cat as cat where " +
cat.id in ( ?, ?)",
new Object[] { id1, id2 },
new Type[] { Hibernate.LONG, Hibernate.LONG }
);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 9:56 am 
Newbie

Joined: Sun Oct 26, 2003 4:46 pm
Posts: 16
Location: Tallinn, Estonia
hi,

sorry, I was a bit unclear in my original question - yes I know you can do like your example.

But I was thinking of something like this:

Code:
String[] statuses = {"A", "B", "C"};
List result = session.find("from X x where x.status in (?)", statuses, Hibernate....);

Because I didn't want to hardcode the number of statuses that are looked for.

I know you can do this like this:

Code:
Query query = session.createQuery("from X x where x.status in (:statuses)");
query.setParameterList("statuses", statuses);
List result = query.list();

So I was wondering if this is somehow possible without creating a Query object.

But I think it is not because now I looked at the debug log from the Query it seems that it creates an HQL statement using three parameters inside IN clause.

best regards,
erik


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

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.