|
|
|
Hibernate 3.1.3
Postgres 7.4.8 Java 1.5.0_06 I fairly certain I'm having the same issue. Code of the form fails: // first session Experimenter e = (Experimenter) session.get(Experimenter.class, 0); expVersion = e.getVersion(); Project p = new Project(); p.getDetails().setOwner( e ); p = session.merge( p ); Long id = p.getId(); // second session p = (Project) session.createQuery("from Project p " + " join fetch p.details.owner " + " where p.id = :id "). setParameter("id",id ).uniqueResult(); p.setName( " updated " ); p = (Project) session.merge( p ); // third session Experimenter e = (Experimenter) session.get(Experimenter.class, 0); assertTrue(expVersion.equals(e.getVersion())); Preparing a test case now. TypeFactory.replace seems to be setting the "dirty=true" in AbstractPersistentCollection by calling clear on PersistentSet which calls dirty(). (Will attach a screen shot momentarily) Screenshot showing the call to AbstractPersistentCollection.dirty() in Eclipse debugger.
hhh1401 directory with test case, two java beans, two hbm files to be copied to <HIB>/test/org/hibernate/test. Output of intersted (with show_sql=true) is:
Hibernate: select nextval ('hibernate_sequence') Hibernate: insert into experimenter (version, id) values (?, ?) Hibernate: select experiment0_.id as id0_1_, experiment0_.version as version0_1_, groupexper1_.child as child3_, groupexper1_.id as id3_, groupexper1_.id as id1_0_, groupexper1_.version as version1_0_, groupexper1_.child as child1_0_ from experimenter experiment0_ left outer join groupexperimentermap groupexper1_ on experiment0_.id=groupexper1_.child where experiment0_.id=? Hibernate: update experimenter set version=? where id=? and version=? This final update is unnecessary since we are simply merging an extant Experimenter: // Create our data Session s = openSession(); Transaction t = s.beginTransaction(); Experimenter e = new Experimenter(); e = (Experimenter) s.merge( e ); s.flush(); t.commit(); s.close(); // Do our problematic merge. s = openSession(); t = s.beginTransaction(); Experimenter e2 = (Experimenter) s.merge( e ); s.flush(); t.commit(); s.close(); assertTrue( "Version was incremented although we did nothing", e.getVersion().equals( e2.getVersion() ) ); I can also confirm that removing the <version/> mappings prevents the unnecessary updates. Output of interest (and not "intersted") is:
Hibernate: select nextval ('hibernate_sequence') Hibernate: insert into experimenter (id) values (?) Hibernate: select experiment0_.id as id0_1_, 0 as formula0_1_, groupexper1_.child as child3_, groupexper1_.id as id3_, groupexper1_.id as id1_0_, groupexper1_.child as child1_0_, 0 as formula1_0_ from experimenter experiment0_ left outer join groupexperimentermap groupexper1_ on experiment0_.id=groupexper1_.child where experiment0_.id=? Apparently there are others having similar issues without the merge method. See
Confirmed test failure for:
Revision: 10123 (~3.2.cr2) HQL dialect. These tests failed as well:
[junit] TEST org.hibernate.test.cuk.CompositePropertyRefTest FAILED [junit] TEST org.hibernate.test.hql.ASTParserLoadingTest FAILED [junit] TEST org.hibernate.test.hql.CriteriaHQLAlignmentTest FAILED [junit] TEST org.hibernate.test.hql.HQLTest FAILED [junit] TEST org.hibernate.test.optlock.OptimisticLockTest FAILED [junit] TEST org.hibernate.test.orphan.PropertyRefTest FAILED [junit] TEST org.hibernate.test.propertyref.PropertyRefTest FAILED [junit] TEST org.hibernate.test.readonly.ReadOnlyTest FAILED [junit] TEST org.hibernate.test.sql.GeneralTest FAILED OptimisticLock, naturally, seems to be significant. Attaching the test log here. Attached new HHH1401Test (replaces version in zip). Has second test using collections which fail despite the fixes Steve made to
So in my testing (against the latest code), the only scenario in which I can reproduce this (I am using the entity's defined in org.hhibernate.test.ops) is when merging an unmodified entity which:
(1) is versioned (2) has collection which actually has elements I am still looking into that case. Can anyone else confirm that they do not see this problem in any other scenarios? The collection I am using is specifically an inverse hierarchical Set... All the cases I tested were consistent with Steve Ebersole's test case (I am not aware of any other ones).
So at this point, I have added a bunch of tests now to test this behavior. If anyone is still experiencing issues here, please refer to one of these tests as a baseline for the behavior you see...
The tests consist of a couple new test methods in org.hibernate.test.ops.MergeTest: (1) testNoExtraUpdatesOnMerge() (2) testNoExtraUpdatesOnMergeWithCollection() (3) testNoExtraUpdatesOnMergeVersioned() (4) testNoExtraUpdatesOnMergeVersionedWithCollection() and the new/expanded org.hibernate.test.collection.CollectionSuite For those previously experiencing issues in this area, please check out SVN (3.2 or trunk) and test with my changes... |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The extra updates are **NOT** issued if I remove the mapping for versioning:
<version name="concurrentVersion" column="concurrent_version" type="long"/>