Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Anirban Chowdhury
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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?

 
Hemant Thard
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
This was a spring configuration issue and was resolved by adding @SessionAttributes to my Controller class.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic