-->
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.  [ 5 posts ] 
Author Message
 Post subject: sqlRestriction and IN statement
PostPosted: Tue May 24, 2005 11:12 am 
Newbie

Joined: Mon May 23, 2005 4:23 am
Posts: 4
Hello!

Hibernate 3.0.4

I wish to use sqlRestriction and IN SQL statement. What must I use as third parameter (Type) in Restrictions.sqlRestriction? I wish check values in some Set or List.

Does anyone know how can I alive such code sqlRestriction:
Code:
final Criteria cr = s.createCriteria(Product.class).createCriteria("responsible");

cr.add(Restrictions.sqlRestriction("{alias}.branches IN (?)", u.getBranches(), ???));

//For simple data type everything is easy
cr.add(Restrictions.sqlRestriction("{alias}.firstName like ?", "%", Hibernate.STRING));


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 11:21 am 
Newbie

Joined: Tue Jul 26, 2005 10:12 am
Posts: 4
I'm having the same issue, did you ever find a solution to this?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 11:22 am 
Newbie

Joined: Tue Jul 26, 2005 10:12 am
Posts: 4
I'm having the same issue, did you ever find a solution to this?

Thanks!


Top
 Profile  
 
 Post subject: Re: sqlRestriction and IN statement
PostPosted: Tue Aug 18, 2009 12:28 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
I have the same issue. Any one knows? Thanks.


Top
 Profile  
 
 Post subject: Re: sqlRestriction and IN statement
PostPosted: Thu Jan 14, 2010 11:43 am 
Newbie

Joined: Thu Aug 07, 2008 12:03 pm
Posts: 16
foxyboa wrote:
Hello!

Hibernate 3.0.4

I wish to use sqlRestriction and IN SQL statement. What must I use as third parameter (Type) in Restrictions.sqlRestriction? I wish check values in some Set or List.

Does anyone know how can I alive such code sqlRestriction:
Code:
final Criteria cr = s.createCriteria(Product.class).createCriteria("responsible");

cr.add(Restrictions.sqlRestriction("{alias}.branches IN (?)", u.getBranches(), ???));

//For simple data type everything is easy
cr.add(Restrictions.sqlRestriction("{alias}.firstName like ?", "%", Hibernate.STRING));


You can do the following. It isn't very elegant, but I'm afraid it's your only alternative.

Code:
final Criteria cr = s.createCriteria(Product.class).createCriteria("responsible");

final org.hibernate.type.Type[] types = new org.hibernate.type.Type[catIds.size()];
Arrays.fill(types, org.hibernate.Hibernate.LONG); //Let's suppose you have LONG values inside that getBranches().

final StringBuilder questionMarks= new StringBuilder();
for(int i=0;i<u.getBranches().size();i++){
       if(i>0) questionMarks.append(",");
       questionMarks.append("?");
}

cr.add(Restrictions.sqlRestriction("{alias}.branches IN ("+questionMarks.toString()+")", u.getBranches().toArray(), types));


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.