• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Criteria Issue

 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anirudh Vyas
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic