-->
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.  [ 1 post ] 
Author Message
 Post subject: merge causes unecessary update with <version>
PostPosted: Fri Jul 23, 2010 9:10 am 
Newbie

Joined: Fri Jul 23, 2010 9:00 am
Posts: 1
Hello,
using Hibernate 3.5.2-Final.
The problem (i believe it's a bug) is that hibernate will cause an update to the version when using merge, even when the object has not changed. The issue occurs when replacing a Set reference with a new HashSet in the loaded object.

Here is the mapping to test:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="scanserver.util.hibernate.tests">
  <class name="GroupTest" table="groups" lazy="false" dynamic-update="true">
    <id column="id" name="id">
      <generator class="native"/>
    </id>
    <version column="version" name="version"/>
    <property name="name"/>
  </class>

  <class name="UserTest" table="users" lazy="false" dynamic-update="true">
    <id column="id" name="id"><generator class="native"/></id>
    <version column="version" name="version"/>
    <property name="userName"/>
    <property name="name"/>
    <set cascade="merge,save-update" fetch="join" name="Groups" table="usersgroups">
      <key column="UserID"/>
      <many-to-many class="GroupTest" column="GroupID"/>
    </set>
  </class>
</hibernate-mapping>


Here is the code to reproduce:
Code:
    Session s = getSession();
    s.beginTransaction();
    UserTest u = (UserTest)s.load(UserTest.class, 1);
    s.getTransaction().commit();
    s.close();
   
    //this is the line that causes the problem
    u.setGroups(new HashSet(u.getGroups()));

    s = getSession();
    s.beginTransaction();
    s.merge(u);
    s.getTransaction().commit();
    s.close();


Hibernate executes the following SQL:
Code:
Hibernate:
    update
        users
    set
        version=?
    where
        id=?
        and version=?

Obviously, there is nothing to update here apart from the version!
If the line that replaces the Set is omited, then this update does not occur.

Costas


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

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.