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

How to Detached Hibernate object ??

 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Spring + Hibernate. In my application (running under Spring txn) an object is obtained using Spring Hibernate Template. This object (uses a collection) is modified and used later with in the same function.

My problem is I donot want to save the modifed object and in order to do that I have to use session.evict which makes my code dependent on Hibernate. Is there any other way to detach the object so that any modifications are not saved back to database.

Hope I am looking too stupid to ask this question.

Thanks
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just close the session before you hand your object out to the next layer.

pascal
 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pascal,

Thanks for taking interest.

I cannot close the session as this function(where the object is gettign modified) is called number of times with in same transaction. Also closing session means I have to make explicit close call on session which again makes my code dependant on Hibernate.

Thanks
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do not want to bind to hibernate:

- use JPA. But then you bind yourself to JPA :-)
- Create another layer around hibernate
- ?
At some point you have to make your code dependant on something. And persistence is something that -even with JPA/EJB3.0 - has some parts that makes tool A different from tool B that can not be hidden behind a common interface.


Pascal
 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Pascal,

I am creating a DTO wrapper over Model to avoid importing Hibernate classes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic