This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Spring Hibernate MVC application merge() saves a new object every time.

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am having a peculiar problem. Every time,I call merge, on the session, Hibernate persists a brand new object. I am using Hibernate 3.6 in a Spring MVC application. I do implement equals and hashcode on the model objects which I try to persist. If I try to debug, the equals() isn't invoked at all. I am really not sure what's going on here.

I am using Spring's OSIVF to open and close sessions and AOP to demarcate transactions

My hibernate.cfg.xml


My employee.hbm.xml

My Model classes



My controller



My service and DAO classes



My AOP configs



The tx. demarcation works correctly , as the new object is persisted successfully, however, after saving the get returns the old object. If I use saveorupdate() instead of merge, it saves a new object,detaches the old object and attaches the new obj. to the session. Can somebody please help me on this?

 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anirban,

Any particular reason why you have overridden hashcode method in your application.

Also can you please be more clear about this statement.

If I use saveorupdate() instead of merge, it saves a new object,detaches the old object and attaches the new obj. to the session.

.

Regards,
Hemant
 
Anirban Chowdhury
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was a spring configuration issue and was resolved by adding @SessionAttributes to my Controller class.


 
You showed up just in time for the waffles! And 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
reply
    Bookmark Topic Watch Topic
  • New Topic