-->
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: Trying to create a query
PostPosted: Thu Sep 22, 2005 3:45 pm 
Newbie

Joined: Sat Mar 19, 2005 3:25 am
Posts: 9
Hi All,

Here is what I have

Table1 = Item
Table2 = WorkspaceMember
Table3 = Trustee

Item.java, WorkspaceMember.java and Trustee.java exist along with their XML files.

Item has 1..M WorkspaceMember which has 1..M Trustees

I want to construct a findByExample query that will find all Items which contain Trustee x

Here is the SQL as I am seeing it.

select a.* from Item a, WorkspaceMember b, Trustee c
where a.rID = b.parentID
and b.trusteeID = x

How do I structure the sequence of calls. Do I use Criteria? How do I build the join up.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 22, 2005 4:26 pm 
Beginner
Beginner

Joined: Thu Sep 15, 2005 4:16 pm
Posts: 29
Just an opinion, but you really need to move from thinking about db joins to thinking in terms of objects. You don't really show your object fields or relationships, but let's say that Item has a members field that holds a set of WorkspaceMember objects and WorkfspaceMember has a trustees member that holds a set of Trustee objects.

One approach would be to query in HQL, something like this:

"SELECT * FROM Item WHERE members.trustees.trusteeID = :tid"

Another approach would be to use Criteria, adding the path. Something like this:

Criteria c = session.createCriteria(Item.class)
.createAlias("members", "member")
.createAlias("trustees", "trustee")
.add(Restriction.eq("member.trustee.trusteeID", id);

Just take a look at the doc on the Criteria interface for examples.


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.