This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

onetomany - hibernateTemplate

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic