-->
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: query problem with many-to-many
PostPosted: Thu May 06, 2004 2:01 am 
Newbie

Joined: Fri Mar 26, 2004 12:05 pm
Posts: 3
I have the following query problem:

Class Base has a Set that holds references to objects of type D. This relationship is modeled as one-to-many.
Further on class Base has a Set with objects C (one-to-many) and C has two Sets that hold also references to objects of type D. The two D-Sets of C are modeled as many-to-many.

Therefore the associations between the objects is of this kind:

Code:
      |->D
Base->C
|    |->D
|->D


Now I want to create a HQL-Query that queries the D. Is it possible when starting from Base-object to query the D from Base->D and also the D from C->D in one HQL-Query?

Many thanks,

Mika


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 6:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
union is not possible
But you can return a cartesian product select d1, d2, d3 from ... I don't think it'll fit your needs

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 6:35 am 
Newbie

Joined: Fri Mar 26, 2004 12:05 pm
Posts: 3
thanks for the reply!

I added a many-to-one association from D to Base in the D-Mapping and selects the D by this query

Code:
select d from Base as b, D as d where d.base = b


Tests show that it works, but is this recommended? Besides the association between Base->D the Base and D have no direct association but an indirect association over C.

Many thanks,

Mika


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 11:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
select d from Base as b join b.cs as c join c.ds where d.base = b

Will not break you relational model

_________________
Emmanuel


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.