-->
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: How do I represent dynamic query in Hibernate?
PostPosted: Thu Jun 23, 2005 5:49 pm 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
Hi there,

I'm from iBatis background and recently started exploring Hibernate. My task is to convert ORMapping layer from iBatis to Hibernate. Simple queries presented in iBatis sql map can easily be converted as per hibernate sql syntax. But I couldnt find a way to represent below query in hibernate format.

this is a search query which is dynamically formed at runtime based on search criteria specified. What alternative do we have in hibernate to represent <isNotEmpty/> kinda functionality? How would I write the below query in hibernate syntax?

<select id="search" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
select CustomerNumber, Name, RXVolume, City, State, Phone, email from Customer
<dynamic prepend=" where ">
<isNotEmpty property="CustomerNumber" prepend=" and ">CustomerNumber like #CustomerNumber# + '%'</isNotEmpty>
<isNotEmpty property="Name" prepend=" and ">Name like #Name# + '%'</isNotEmpty>
<isNotEmpty property="RXVolume" prepend=" and ">RXVolume like #RXVolume# + '%'</isNotEmpty>
<isNotEmpty property="State" prepend=" and ">State like #State# + '%'</isNotEmpty>
</dynamic>
</select>


Thanks in advance.. I'd really appreciate your help in this.

Regards
Nilesh


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 6:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use a Criteria query.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 9:08 am 
Beginner
Beginner

Joined: Tue Jun 21, 2005 1:45 pm
Posts: 38
gavin wrote:
Use a Criteria query.


Thanks gavin.

Criteria query seems to be a good option... My only hesitation is now I'd have to write java code to form SQL queries. I can try to write a generic program which will parse thro XML and then form Criteria query accordingly.

It would be really cool if hibernate can provide a way to embedd criteria query in XML or HQL format. This will avoid plenty of coding + all sql queries can be maintained in a seperate repository.

Well, thanks again, gavin.

~ Nilesh


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.