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: How to solve this: UserManagement
PostPosted: Thu Sep 20, 2007 8:41 am 
Newbie

Joined: Tue Sep 18, 2007 5:19 am
Posts: 6
Hi,

i'm very new to Hibernate and need some help how to set up the following scenario:

I got a Class "User" with attributes
int userid
String prename
String lastname
User manager
List<User> employees

ID should be the primary key, prename / lastname should be the name and manager should be another user of this class type. The list employess should save this relation the other way and make it possible to access sub-ordinated employess from an user who is a manager.

everything seems to work fine, but i doesn't know how to set up this self-relation to another manager / employess.

sombebody got a hint for me ?
a user should have exactly one manager and could have other employess under himself.

thx in advance![/list][/list]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 12:46 pm 
Newbie

Joined: Tue Aug 07, 2007 2:31 am
Posts: 11
If you are using annotations and have the DB schema:

create table UserExample (
id integer not null auto_increment,
lastName varchar(255),
preName varchar(255),
manager_id integer,
primary key (id)
)

You can use the following annotations setup for your class:

@Entity
public class UserExample {

@Id @GeneratedValue(strategy=GenerationType.AUTO)
private Integer id = null;

@Column(length = 255, nullable = true)
String preName;

@Column(length = 255, nullable = true)
String lastName;

@ManyToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
UserExample manager;

@OneToMany(mappedBy = "manager", fetch = FetchType.LAZY, cascade=CascadeType.ALL)
List<UserExample> employees;
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 21, 2007 2:29 am 
Newbie

Joined: Tue Sep 18, 2007 5:19 am
Posts: 6
thx for your assistance.
i'm using an hbm.xml configuration file to handle my project.
can you supply the correpsponding xml tags ?

thx in advance !


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.