-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Why does Hibernate Entity Manager load object at merge?
PostPosted: Mon Dec 10, 2007 11:23 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 3:29 pm
Posts: 23
Hibernate version: 3.2.5

We've being using Hibernate for many years now and we love it. Recently, we found that the Hibernate Entity Manager - when asked to merge using a long transaction - will actually load the object again from the database (if its not available in the first or second level cache). Why does it do this? Why does it not simply use the detached object? Hibernate saveOrUpdate doesn't load the object, why does merge?

In addition to inefficiency, this causes problems when you load object using native queries. Hibernate will generate its own query during merge and this may clash with the mapping.

I miss the older, simpler Hibernate days...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 15, 2007 9:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This was a decision mad in the EJB 3.0 expert group. Both semantic (merge and saveOrUpdate) have merits.
You can always do ((Session) entityManager.getDelegate()).saveOrUpdate()

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 17, 2007 11:08 am 
Beginner
Beginner

Joined: Mon Dec 26, 2005 3:29 pm
Posts: 23
Thanks for your reply. I was hoping to stay away from direct hibernate calls. But I ended up doing something very similar to your suggestion by injecting an entity manager proxy that delegates to hibenrate. This way my code remains clean.

Thanks again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.