This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

onetomany - hibernateTemplate

 
Ranch Hand
Posts: 163
  • 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.
 
Ranch Hand
Posts: 131
  • 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
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic