-->
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: Employee-Manager relationships
PostPosted: Sun Jan 29, 2006 6:47 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Hai,

This is related to my previous post:
http://forum.hibernate.org/viewtopic.php?t=954696


I have a table EMPLOYEE with the following columns.

1. EmployeeId
2. Employee name
3. ManagerId (Foreign key on the same table's (EMPLOYEE table) EmployeeID)


Now I should be able to insert 2 Employee objects First one is the
manager of second Employee.

When I save an Employee Object1 (Employee who is a Manager) it should save it,
generate an Employee ID and use it to store the second Employee Object2 (Employee who is not a manager and has the managerId as the First Object's EmployeeId) all at one go.

How do I achieve it?

If the Manager table and Employee are different Iam able to achieve this?
But how do I do if they are to be updated in the same table?

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 29, 2006 12:01 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Have a cascade="save-update" on the set mapping that contains the members for a Manager. The following code works for me
Code:
       
        Employee manager = new Employee();
        manager.setName("Manager 1");
        manager.setMembers(new HashSet());
        Employee emp = new Employee();
        emp.setName("Employee 1");
        emp.setManager(manager);
        manager.getMembers().add(emp);
        session.saveOrUpdate(manager);


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 29, 2006 11:53 pm 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
[quote][/quote]

_________________
Please vote if my Postings helps. :-)


Last edited by spatik on Mon Jan 30, 2006 5:49 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 5:48 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Actually even Iam using cascade="save-update,persist".
But there is something wrong, which I just couldn't figure out?
Can I see your employee table's hbm file.
Does it have an many-to-one mapping on mangerId?

I also get this exception!!

org.hibernate.PropertyValueException: not-null property references a null or transient value: com.ge.healthcare.gehcit.ehrae.flowsheet.dto.Employee.employee
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:236)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)

Any notion on how to get rid of this??

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 7:05 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Thank you guys.
I got it working now.

_________________
Please vote if my Postings helps. :-)


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.