-->
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.  [ 9 posts ] 
Author Message
 Post subject: Help in Mapping
PostPosted: Thu Apr 10, 2008 1:12 am 
Newbie

Joined: Tue Apr 08, 2008 6:42 am
Posts: 5
Hi,

In my application there is several types of user (Manager,Admin,Employee). I am representing all type of user with User class.Where each user have a manager(reporting person) and Manager has several user.
so i am representing the User class as follows.

public class User {
private Integer id;
private User manager;
private Set<User> subordinateUserList = new HashSet<User>();

..................
}


Now the question is how can i represent this relation in mapping file.
Any help with suggesting code would be great.

-Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 1:31 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Code:
<class name="User" table="user">
<id name="userId" column="user_id">
<generator class="sequence"/>
</id>
<property name="name" column="name" />
<property name="managerId" column="manager_id" />
<set name="subordinateUsers">
<key>
<column name="manager_id" />
</key>
<one-to-many class="User" />
</set>
</class>


Its a self referencing association.

_________________
Sukirtha


Top
 Profile  
 
 Post subject: Help on Mapping
PostPosted: Thu Apr 10, 2008 1:41 am 
Newbie

Joined: Tue Apr 08, 2008 6:42 am
Posts: 5
Hi,
Many many thanks for help.But i dont understand why there is
<property name="managerId" column="manager_id" />
and also following tag in the Set tag.
<key><column name="manager_id" /></key>

can you please describe a bit detail

Thank you once again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 1:50 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
How do you reference a subordinate user's manager in your database? I assume you will use a column that stores the user's manager id. If not then please send me your table design.

_________________
Sukirtha


Top
 Profile  
 
 Post subject: Help on Mapping
PostPosted: Thu Apr 10, 2008 1:57 am 
Newbie

Joined: Tue Apr 08, 2008 6:42 am
Posts: 5
Hi,

I am not thinking about database.Actually i didn't design the database rather i would like to generate database with hibernate. I am doing this process because i just want to separate my application from database implementation.So my process just design the entity(Class) relation and mapping file, rest of the work will be done th Hibernate.


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 2:05 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Hmmm. In that case I'll explain what I am doing in the mapping. The managerId is just a replacement for the manager instance variable you have created in ur java bean. I represent manager using an integer variable instead of a User object.


Code:
public class User {
private Integer id;
private Integer managerId;
private Set<User> subordinateUserList = new HashSet<User>();

..................
}


Not that I am trying to change ur object structure. But when I was faced with a similar scenario, this is how I represented my mapping. But may be u can tweek this a little bit to suit ur structure. :)

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 10, 2008 2:10 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
But I feel your object structure is not right. Why do u need a manager User object inside your user to represent the Manager? wont the manager id suffice?

_________________
Sukirtha


Top
 Profile  
 
 Post subject: Help on Mapping
PostPosted: Thu Apr 10, 2008 2:10 am 
Newbie

Joined: Tue Apr 08, 2008 6:42 am
Posts: 5
Hi,

Thank you for your information.

I would like to add you in my yahoo.my yahoo id is (saiful_raju@yahoo.com)

thanks again


Top
 Profile  
 
 Post subject: Help on Mapping
PostPosted: Thu Apr 10, 2008 2:29 am 
Newbie

Joined: Tue Apr 08, 2008 6:42 am
Posts: 5
User object represents the manager because manager is also a user.
In my application there will be group of users where Admin , Manager and other user may have several subordinates.Think about a software company
where team members are under the Team leader.And team leaders are under the Project Manager.Other stuffs are under the Admin.

My goal is where i can create user(Manager,Admin,Teamlead,Team members) and then assign them under some one.


Your suggestion is welcome for any design issue.

Thanks


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