-->
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: Need advice on a Criteria query
PostPosted: Mon Jun 30, 2008 5:27 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: Wed Jul 02, 2008 4:57 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I am not sure whether you put the cart before the horse here? The criteria API allows you to easily query for entities and restrict results using entity associations. You can only join associated entities. So, if you already managed to create a suitable domain/entity model you should be fine. Generally you can create a association between two entities using composite keys. You basically just specify multiple join columns (either in xml or annotation depending on your chosen configuration).

--Hardy


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.