-->
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: Many to One Association
PostPosted: Mon Jul 26, 2004 3:15 pm 
Newbie

Joined: Sat Jul 24, 2004 10:10 am
Posts: 15
I have two persistent classes Employee and EmployeeType with the two related as

EmployeeType = Employee.getEmployeeType() with emp_type_id as the foriegn key.

Currently I do the following

Employee emp = new Employee() ;
emp.setName ( "xyz") ;

EmployeeType empType = session.get( ......)
emp.setEmployeeType( empType)

session.save( emp);

Can I have the employeeTypeId as an attribute as well as a many to one association defined for the Employee class.

This way I can set the employeeTypeId directly.

Can I do this

Employee emp = new Employee() ;
emp.setName ( "xyz") ;
emp.setEmployeeTypeId( 123);
session.save( emp);

Please advise


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 26, 2004 6:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Not with Hibernate 2.x and on. If employee type is a lazy loaded class then you can do a session.load() as this will not hit the database because a proxy will be created. Otherwise, if no cascading is on then you can create the domain class (new EmployeeType) set its id then assign the new object to the Employee.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I think you can do it using <many-to-one insert="false" udapte="false"/>
but the many to one element will be read only from a DB pespective and you'll have to update manyToOneId by yourself

_________________
Emmanuel


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.