-->
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: Parent version not incremented when child set augmented
PostPosted: Thu Jan 08, 2009 2:37 pm 
Beginner
Beginner

Joined: Thu Apr 13, 2006 12:56 pm
Posts: 23
I am observing that a parent's version is NOT updated when child collection is augmented if another simple property on parent - one with @OptimisticLock(excluded=true) - is also updated in same session.

I have:

Code:
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate = true, dynamicInsert = true)
@Table(name = "parents")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
class Parent{

private String name;

private Set<Child> children;

@OptimisticLock(excluded=true)
public String getName()
{
   return name;
}

public void addChild(Child c)
{
c.setParent(this);
children.add(c);
}

@Version
@NotNull
public Integer getHibernateVersion()
{
return hibernateVersion;
}

}


The following code correctly increments parent's hibernateVersion on flush():

Code:
Parent p = session.get(parentId);
p.addChild(new Child());


//I see SQL like "update parent set hibernateVersion=1 where id=x and hibernateVersion=0"

However, when I also update parent.name, parent's hibernateVersion is NOT updated, even though child collection was altered:

Code:
Parent p = session.get(parentId);
p.addChild(new Child());
p.setName("blah"); //<---------------------


In this case, name is updated, child is inserted, but parent's version is NOT updated. Why? As far as I can tell given @OptimisticLock annotation above getName() should not mask the fact that collection was dirtied...


I confirmed that if I remove @OptimisticLock annotation from getName(), above code snippet results in expected version update on Parent


Hibernate version:
Core 3.3.1GA
Annotations 3.4.0GA


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.