-->
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.  [ 3 posts ] 
Author Message
 Post subject: Ternary Relation Problem
PostPosted: Tue Apr 05, 2005 6:10 am 
Newbie

Joined: Fri Mar 18, 2005 5:35 am
Posts: 8
Hi, i've a problem with realize ternary relation...
I use a very simple example for explain my problem:
DB is composed of four table:
- users (userId,name)
- groups (groupId,description)
- role (roleId,description)
- u_g_r (fk_userId,fk_groupId,fk_roleId)

my problem is that i would have a method on Group class that return the users of this group and theyr role (only roleId that is present in ternary association table... ) ....i would that is realized by hibernate with only query as: select users.userId,users.name,u_g_r.fk_roleId from u_g_r inner
join users on users.userId = u_g_r.fk_userId where u_g_r.fk_groupId = ?

...i try to use (in mapping of group)

<map name="users" table="`u_g_r`" cascade="none">
<key column="`fk_groupId`" not-null="true"/>
<map-key-many-to-many column="`fk_roleId`"class="it.test.Role"/>
<many-to-many column="`fk_userId`" class="it.test.User"/>
</map>

...or composite elements:

<set name="users" table="`u_g_r`">
<key column="`fk_groupId`" not-null="true"/>
<composite-element class="it.test.UserRole">
<property column="`fk_roleId`" name="roleId"/>
<many-to-one name="user" class="it.unitn.cs.hibernate.User" column="`fk_userId`"/>
</composite-element>
</set>

...but this realize n° query for retrieve user information (one for each user in u_g_r )...

I would that group contains an collection of UserRole; this class has two properties user and roleId... how realize this with Hibernate (populated this class with only query and not with n° query for each user!)?

Thanks in advance!


Top
 Profile  
 
 Post subject: Ternary Relation
PostPosted: Tue Apr 05, 2005 10:38 am 
Regular
Regular

Joined: Fri Mar 04, 2005 1:33 pm
Posts: 65
Location: U.K.
refer to

http://www.xylax.net/hibernate/ternary.html


Top
 Profile  
 
 Post subject: Re: Ternary Relation
PostPosted: Wed Apr 06, 2005 3:42 am 
Newbie

Joined: Fri Mar 18, 2005 5:35 am
Posts: 8
Thanks...i've just read this article, but the proplem persist...
If i have the class:

A -> property idA , nameA (mapping on table a_example)

B -> property idB, nameB (mapping on table b_example)

C -> property idC, nameC (mapping on table c_example)

and it's present a relation table a_b_c whith fk_idA,fk_idB and fk_idC

Now i use the composite-elemen descript on article (in mapping of class A):

adding an get/set D method on A; where D is the class that rappresent relation (this has get/set B and get/set C method)

BUT if i load A and call getD the field D.B and D.C is not loaded (hibernate use lazy load and load this field only when i accessed they) the result is an query for all B and C present on D ...=(n° x 2) query where n is the number of B/C present for A in relation...

I would that Hibernate initialize it's with only query (because i use only the B.idB present in a_b_c and not all "Object" B)
like this:
select a_b_c.idB,c_example.idC,c_example.nameC from a_b_c inner join c_example on a_b_c.fk_idC = c_example.idC where a_b_c.fk_idA = ?
my composite element D must have only
idB and C fields....

It's possible realize this with Hibernate? Because if i more elements for A (m number) the query produced is (n° x 2) x m respect only 1 (because i don't use the all B object but only it' id that is present in ternary table...)!

Thank in advance
Alessio


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