-->
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: merge() causes version to increase
PostPosted: Fri Oct 06, 2006 11:30 pm 
Newbie

Joined: Thu Jun 16, 2005 5:21 pm
Posts: 6
I'm finding that calling merge() on an unmodified entity results in the entity being marked dirty and hence its version number is increased and an SQL UPDATE performed on it.

I've provided a test case at (packaged as a complete eclipse 3.2 project). See http://opensource.atlassian.com/projects/hibernate/browse/EJB-237. Set EJB3_HOME, HIBERNATE_HOME and HSQLDB_HOME in your eclipse workspace preferences and then run the included PojoTest launcher to see it run.

The test populates the DB, does a select by name, merge, merge and select by name again. Each of these five steps is in its own Tx and entity manager. The pojo is not being modified (by my code) between the merge calls(), yet I get the following output (each print is before the commit following the operation):

Code:
findByUniqueName: pojo1 version=0
merge: pojo1 version=0
merge: pojo1 version=1
findByUniqueName: pojo1 version=2


The test also produces a hibernate.log trace file which shows :

Code:
processing cascade ACTION_PERSIST_ON_FLUSH for: com.acme.test.Pojo [org.hibernate.engine.Cascade.cascade(Cascade.java:115)]
cascade ACTION_PERSIST_ON_FLUSH for collection: com.acme.test.Pojo.attributes [org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:291)]
done cascade ACTION_PERSIST_ON_FLUSH for collection: com.acme.test.Pojo.attributes [org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:306)]
done processing cascade ACTION_PERSIST_ON_FLUSH for: com.acme.test.Pojo [org.hibernate.engine.Cascade.cascade(Cascade.java:150)]
dirty checking collections [org.hibernate.event.def.AbstractFlushingEventListener.prepareCollectionFlushes(AbstractFlushingEventListener.java:153)]
Collection dirty: [com.acme.test.Pojo.attributes#2] [org.hibernate.engine.CollectionEntry.preFlush(CollectionEntry.java:177)]


In http://forum.hibernate.org/viewtopic.php?t=965119 it was stated that
Quote:
an entity is only updated on merge() if one of its properties/associations fails isEqual().

I'm not seeing isEqual get called. The merge() call marks the 1..N association from my entity as dirty - the collection is marked dirty on return from the merge(). When the dirty check is later made during commit(), CollectionEntry.dirty() sees the dirty mark when it calls collection.isDirty() and doesn't get to call collection.equalsSnapshot().

Any insight into what's going on here is appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 3:20 pm 
Newbie

Joined: Thu Jun 16, 2005 5:21 pm
Posts: 6
From the Hibernate home page: "
Quote:
Hibernate 3.2.0.CR5, Hibernate Annotations 3.2.0.CR3 and Hibernate EntityManager 3.2.0.CR3 have just been released. We decided to do one more CR release before GA, with the following updates: (1) a fix for the JPA "persist on flush" event (EJB-221) and (2) a performance improvement with regard to flush processing (HHH-2093).


I didn't realize you were this close to GA. I see from my JIRA entry that this merge() issue is a Hibernate bug. I cannot imagine how you can ship with this issue outstanding - it's an absolute stopper for our application. We're currently getting constant OptimisticLockExceptions due to these spurious updates.

BTW - I've just retested with CR5 and CR3. Unsurprisingly, given the JIRA comments, it still fails.

Will this be fixed for GA? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 5:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ohpb2003 wrote:
Will this be fixed for GA?

No, the case will not be taken care of in the GA

_________________
Emmanuel


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.