-->
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: What is the best way to perform join in Hibernate
PostPosted: Fri Dec 10, 2004 12:39 pm 
Newbie

Joined: Sun Nov 14, 2004 1:28 am
Posts: 2
Hibernate version:2.0

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:mySQL

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

suppose I have two tables, A and B. A is the parent and B is the child with one-to-many relationship from A to B. I want to get all the data like this:

select * from A, B
where A.key1 = B.key1 -- key joins
and A.field1 = 'abc'
and B.field1='xyz'

I know a few ways to do it:

1. filter by A first then loop through B's collection to get all the matches. I don't think it is a good way
2. write the join in Java code like this:
session.find(" select a from A as a join B as b where ...")

Is there a better way to do it? How can we extract the SQL out from Java code to some XML files? Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 2:33 pm 
Regular
Regular

Joined: Thu Oct 07, 2004 4:45 pm
Posts: 92
Session#getNamedQuery(String)


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.