-->
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: Please Help on this Mapping Problem.
PostPosted: Tue Oct 31, 2006 4:09 pm 
Newbie

Joined: Tue Oct 31, 2006 4:06 pm
Posts: 7
I have some difficulty to find the right solution for the mapping problem I have here.

I have a User class which has two business methods: getCoWorkers() and getDirectCoWorkers(). Direct co-workers are a subset of co-workers. Both methods return a collection of User objects. The relationship between users and co-workers is many-to-many, and it's unidirectional from users to co-workers. Since direct co-workers are co-workers, I don't want to keep two copies of the same user in the object.

The table of the relationship is like:

id (synthetic primary key)
user_id
co_worker_id
co_worker_flag (indicating whether this co-worker is a direct co-worker)

Anyone can help out on this?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 5:40 pm 
Newbie

Joined: Tue Jul 25, 2006 6:40 pm
Posts: 6
Location: Plano, TX
Why not make the getDirectCoWorkers() a transient method?

You can use your getCoWorkers() to return the set of coworkers with the flag, then DirectCoWorkers can just filter that collection and return the subset.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 31, 2006 8:40 pm 
Newbie

Joined: Tue Oct 31, 2006 4:06 pm
Posts: 7
Will the following code work based on the suggestion?

public User()
{
}


pubic CoWorkerRelationship
{
private User user;
private User coWorker;
private String directCoWorkerFlag = "N";
}


In User.hbm.xml use this to map the relationship:

<set name="coWorkers" lazy="true" table="co_worker_relationship">
<key column="user_id">
<composite-element class="CoWorkerRelationship">
<parent name="User">
<many-to-one name="coWorker" class="User" column="co_worker_id" not-null="true"/>
<property name="directCoWorkerFlag" column="co_worker_flag" not-null="true"/>
</composite-element>
</set>


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