-->
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.  [ 2 posts ] 
Author Message
 Post subject: dynamic queries
PostPosted: Wed Feb 07, 2007 6:14 am 
Beginner
Beginner

Joined: Thu Aug 10, 2006 2:06 am
Posts: 26
hi all,

does hibernate support dynamic queries?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 6:43 am 
Newbie

Joined: Tue Dec 12, 2006 3:19 am
Posts: 17
Location: Spain
Hello,
Do you mean:
1) to build the where clause dynamically adding new restrictions?
2) or to specify the value of some attributes of the where clause?

You can code both of them.

1) Using criteria API, you may add the Restriction you need.
Code:
Criteria criterio = session.createCriteria(XXX.class);
if(name.compareto("")!=0)
criterio.add(Restrictions.eq("name",(Boolean) name) ));

For more information about this:
http://www.hibernate.org/hib_docs/v3/re ... teria.html

2) Using .setParameter (and the similar methods)
Code:
String Name;
Name="me";
session.createQuery("from XXX where name=:n")
.setParameter("n", Name)
.list();

For more information about this:
http://www.hibernate.org/hib_docs/v3/re ... e-querying

_________________
Please, rate this posting if you find it useful


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