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.  [ 5 posts ] 
Author Message
 Post subject: many to many mapping
PostPosted: Tue Jan 06, 2009 1:12 pm 
Newbie

Joined: Tue Jan 06, 2009 1:02 pm
Posts: 3
I have a user class and a device class.
i need to add properties to a table,
this table is created via the user.hbm.xml by many-to-many declaration
as follows:

<bag name="Devices" table="tbl_Workouts" lazy="false">
<key column="user_id"/>
<many-to-many class="DAL.Entities.Device, DAL" column="device_id"/>
</bag>

the result is a table with a user_id and device_id keys
I need to add properties to this table but cant find help anywhere on the net on how to do so.

your help is required


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2009 8:12 pm 
Newbie

Joined: Sat Nov 29, 2008 6:59 pm
Posts: 19
Location: Burlington, VT
It sounds like you have a many-to-many relationship with additional properties. A similar example is a relationship between Employees and Projects with the Employee having a Role on the Project.

If this is the case, I would usually model the link (many-to-many) table as an entity with a many-to-one relationship to each side of the relationship. So you would have a UserDevice entity. User and Device would both have a one-to-many relationship with UserDevice.


Top
 Profile  
 
 Post subject: new lead
PostPosted: Wed Jan 07, 2009 1:45 pm 
Newbie

Joined: Tue Jan 06, 2009 1:02 pm
Posts: 3
I just started doing so but in a sllitly diffrent version:
i created a class DeviceUsage which inherits device and adds properties.
now all i need to do is change the user.hbm.xml bag mapping from "many-to-many" to "one-to-many" and replace the device with deviceusage inside the bag.
do u think it would work ?
(anyway thanx for your previous reply)


Top
 Profile  
 
 Post subject: no can do
PostPosted: Wed Jan 07, 2009 2:01 pm 
Newbie

Joined: Tue Jan 06, 2009 1:02 pm
Posts: 3
Took me 5 minutes to see my idea would not work.
Implementing your idea is the best solution
i'm having trouble underestanding somthing tough..

in this case the user and device have hbm.xml without connection to any other entity, on the other hand the userdevice actually keeps the user_id and device_id data ?


Top
 Profile  
 
 Post subject: Re: no can do
PostPosted: Wed Jan 07, 2009 2:58 pm 
Newbie

Joined: Sat Nov 29, 2008 6:59 pm
Posts: 19
Location: Burlington, VT
User will have a UserDevice collection (one-to-many)
Device will have a UserDevice collection (one-to-many)
UserDevice will have User and Device properties (both one-to-many)

yanivtech wrote:
Took me 5 minutes to see my idea would not work.
Implementing your idea is the best solution
i'm having trouble underestanding somthing tough..

in this case the user and device have hbm.xml without connection to any other entity, on the other hand the userdevice actually keeps the user_id and device_id data ?


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