-->
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.  [ 1 post ] 
Author Message
 Post subject: Employee Manager Classes on same table
PostPosted: Sun Jun 20, 2004 3:23 pm 
Newbie

Joined: Sun Jun 20, 2004 3:06 pm
Posts: 5
In the classic employee table as below
empid (pk)
Name
managerid

Where managerid is FK to empid. I have an employee class as below
public class Employee{
private Long empid;
private String firstName;
private String lastName;
private Employee manager;
}

Where there is many-to-one on manager with Employee class on managerid.

So setting an already persisted employee to a new Employee updates the managerid column of that emplyee wiht the previous one. All good.

However I also want to create a Manager class like so
public class Manager {
private Long empid;
private String firstName;
private String lastName;
private Set employees;

where I have the following tags for employees (using hibernatedoclet to gen mapping file).

@hibernate.set name="employees"
* lazy="true" inverse="true" cascade="all"
* @hibernate.collection-key column="managerid"
* @hibernate.collection-one-to-many class="Employee"


However a test like so --


Employee emp1 = new Employee();
.....
Employee emp2 = new Employee();
....
Set employees = new HasSet();
employees.add(emp1);
employees.add(emp2);

Manager mang = new Manager();
mang.setemployees(employees ) ;

session.saveorupdate(mang);

Saves all three records to the database. However the managerid column of emp1 and emp2 records are null.

What is it that I am missing here? I've spent quite a bit trying to figure out to no avail.

Thanks
Kumar


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.