aspose file tools*
The moose likes Object Relational Mapping and the fly likes Criteria Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria Issue" Watch "Criteria Issue" New topic
Author

Criteria Issue

Anirudh Vyas
Ranch Hand

Joined: Oct 23, 2006
Posts: 93
Hi,

I have two tables say X and Y, with a join table X_Y. now there is a Z table which can be associated with X and Y tables somehow (with a foreign key).

But my issue is that I have a U table which is not associated with X and Y or Z for that matter in any ways. How do I :
Write query for such a scenario? (meaning how will hibernate be able to generate where U.id = "SOME_ID" for a query on X and y); to illustrate heres what i mean :

Select x_.Name,
y_.name,
from X x_
LEFT OUTER JOIN
X_Y ASSOCIATE_
ON ASSOCIATE_.ID = x_.ID
LEFT OUTER JOIN
Y y_
ON ASSOCIATE_.ID = y_.ID
WHERE U.ID = ?

Any kind of help (you can tell me the SQL too ... )

Rick.
[ April 03, 2008: Message edited by: Anirudh Vyas ]

Vyas, Anirudh
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Actually it looks like you have it already. When you query the data you will have to add it to the Where clause. So in Criteria add a Restriction, for Query use the object in the Where clause, and in SQLQuery objects exactly how you wrote it in your post.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Anirudh Vyas
Ranch Hand

Joined: Oct 23, 2006
Posts: 93
hey ... yea i was able to sort that out; added a simple restriction (d-oh, i was full of it last night because of work and all)

Thanks for your help.

Regards
Vyas, Anirudh
 
wood burning stoves
 
subject: Criteria Issue