aspose file tools*
The moose likes Other Application Frameworks and the fly likes onetomany - hibernateTemplate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "onetomany - hibernateTemplate" Watch "onetomany - hibernateTemplate" New topic
Author

onetomany - hibernateTemplate

Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Hi,
I have a problem with Spring-Hibernate one to many application.

I have saved Dept object ( parent).
To save an emp ( child ) object to the database, i am using dept.getEmps().add( emp). Here dept.getEmps() returns a Hash set.

When i use only hibernate API it is working fine. emp object is added to the database and it is added to dept children.

But when i use the same concept for hibernateTemplate it is not working. Can any one of you tell me the mistake in the application.












Problem is, emp is getting added to dept's hashset but not to the database.
When i use hibernateTemplate.update(dept), emp is getting added to the database here. But when i use only hibernateAPI i.e. with out springs, with out using session.update(dept), emp is getting added to database. can you pls tell me the mistake in this application.
Manuel Jordan
Ranch Hand

Joined: Sep 29, 2006
Posts: 131
Hello Naresh

I have saved Dept object ( parent).
To save an emp ( child ) object to the database, i am using dept.getEmps().add( emp). Here dept.getEmps() returns a Hash set.


parent and child, where??? i dont understand, in your mapping files i see a simple relation and looks good.


When i use hibernateTemplate.update(dept), emp is getting added to the database here. But when i use only hibernateAPI i.e. with out springs, with out using session.update(dept), emp is getting added to database. can you pls tell me the mistake in this application.


the correct way is using the "update method", mistake???, no exist i think so.

maybe this is wrong , long time ago that i dont work with hibernate alone,
i work with Spring/Hibernate
but i can remember and you see this behaviour: you can update into the db only with Hibernate without use update method, why??, this is a feature of Hibernate, automatic update into the dabase when the state of the object (values of the properties) is changed

in Spring not happens, you must use the hibernateTemplate

regards


kill your pride, share your knowledge with all
 
 
subject: onetomany - hibernateTemplate