-->
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.  [ 4 posts ] 
Author Message
 Post subject: JDBC join migrated to Hibernate
PostPosted: Thu Jun 08, 2006 1:39 pm 
Newbie

Joined: Sat Mar 18, 2006 1:13 am
Posts: 10
I'm in the process of rewriting some legacy JDBC into hibernate, but am struggling with how to convert a given query. Or more to the point, I'm struggling with 'Is it a good idea to convert said query'.

The query joins 2 tables A and B via a 3rd table C. It returns the distinct values of a column from A and a column from B.

select distinct A.col, B.col
from A, B, C
where A.id = C.A_id
and B.id = C.B_ID

Clearly, I could brute force this modelling A, B, and C (A having a Set of C's, B having a set of C's, etc.), getting a list of A and walking on down. This seems rather heavy handed though. Not to mention, it turns a somewhat elegant SQL query into some hideously blunt code.

Surely there's a way to move a straightforward SQL join into Hibernate in some fashion.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 1:46 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
A many-to-many to B

like in :
unidirectional many-to-many association

or :

bidirectional many-to-many association

And Chapter 14 explains quit a lot about HQL...

You can than do something like:

Code:
  from A
  inner join fecth a.bs
  //bs set of object B in class A


Hibernate will resolve for you through the mapping how to get from A to B

Good Luck!

_________________
Don´t forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 5:01 pm 
Newbie

Joined: Thu Jun 08, 2006 3:25 pm
Posts: 5
Location: Laureldale, PA
What if you created a view and then mapped to that through hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 6:25 pm 
Regular
Regular

Joined: Thu Sep 22, 2005 1:53 pm
Posts: 88
Location: Rio de Janeiro
ronb722 wrote:
What if you created a view and then mapped to that through hibernate?


I have never done it but as far as I know this is no problem

_________________
Don´t forget to rate!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.