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