File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

onetomany - hibernateTemplate

 
Naresh Gunda
Ranch Hand
Posts: 163
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic