-->
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: Inversion of Employee-manager relationship !!!
PostPosted: Mon Jan 30, 2006 9:31 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Hi,
Iam able to achieve Employee manager relationship by creating Employee object First and then adding the manager Object to it and getting both objects persisted the right way.

refer post: http://forum.hibernate.org/viewtopic.php?t=954771


But I need to create the manager Object first and add employees to the manager object and get them persisted.
I should only give session.save(Manager) instead of session.save(Employee).

Is there any specific changes I need to make to the hbm file for this?
I tried it and was not able to achieve it.

I don't know if this question is really dumb. :-(

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject: RE: Inversion of Employee-manager relationship
PostPosted: Mon Jan 30, 2006 11:21 am 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
The first reply to your other post seems to be exactly what you are asking for here, isn't it?

_________________
-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 12:51 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
errr....
Actually I din't understand what you said?
:-(

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 9:39 am 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
You said that this is what you need: "But I need to create the manager Object first and add employees to the manager object and get them persisted.
I should only give session.save(Manager) instead of session.save(Employee). "

And in the link you posted, one of the replies says the following:

Have a cascade="save-update" on the set mapping that contains the members for a Manager. The following code works for me

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);



The will let you add employees to the manager, and just save the manager. Cascade is the key for making that happen. Isn't this what you are asking?

_________________
-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 9:54 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Hey.
I got it worked. I was so dumb!!! :-(

Any way thanks for the reply buddy. :-)

_________________
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.