-->
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: Advice on a Criteria query needed, thanks.
PostPosted: Tue Jul 01, 2008 12:06 pm 
Beginner
Beginner

Joined: Thu Feb 28, 2008 11:53 am
Posts: 23
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2

Name and version of the database you are using: Oracle 10g

I have this somewhat verbose query
Code:
select sr.id, r.date_created, sr.product_group, sr.territory, u.unitid, u.code,
u.name, u.unit_typeid, u.countrytypeid, u.country, col.collectionid, col.code as col_code,
col.name as col_name, col.componenttypeid as col_componenttypeid, cs.cstateid, cs.code as cs_code,
cs.name as cs_name, cs.shortcode as cs_shortcode
from req r
inner join some_req sr on sr.id = r.id
inner join req_collection rc on rc.id = r.id
inner join collections col on col.collectionid = rc.collection_id
inner join req_cstate rcs on rcs.req_id = rc.id and rcs.collection_id = rc.collection_id
inner join cstates cs on cs.collectionid = rcs.collection_id and cs.cstateid = rcs.cstate_id
inner join unit_requr on ur.id = r.id
inner join units u on u.unitid = ur.unit_id
inner join user_units uu on uu.unit_id = ur.unit_id
inner join sessions s on s.user_id = uu.user_id where s.id = 833


I'm moving to Hibernate cause I require the use and simplicity of the Criteria artefacts but I don't think I can implement this query by associations (such as in the case where a class is associated by 2 properties). Can I mirror these inner joins with Criteria, I know I can use createAlias but how do I join objects at 2 points ? Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 11:03 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
With the Criteria API, you really need to think in terms of objects, not in terms of tables. What do your objects look like? From there, we can easily create the Criteria API query.

Here's a little tutorial on using the Criteria API that you might find helpful:

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=09howtousethecriteriaapi

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.