I'm using jpa with hibernate (3.2.7) as orm implementation. I have an entity being modified and then merged. I also have an @EntityListeners on this entity to ensure some attribute being valued.
If I change a value before merge, and then change back that value in @PreUpdate method inside Listener, setting the original value, my version on entity results incremented, but on database version has previous value. I think this is due to object didn't change, so on db it's not updated, but version on entity was alredy incremented without being restored after flush.
To explain better, i have this object:
@Entity
@EntityListeners({MyListener.class})
public class MyEntity {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
private String myValue;
@Version
private Long version ;
}
and this Listener:
public class MyListener {
@PreUpdate
public void preUpdate(MyEntity ua) {
ua.setMyValue("default");
}
}
Now suppose i have on db an object with these values: (id=1, myValue='defalut', version=1). I read this object, detach, pass it to client and get it back with myValue='new' and perform a merge operation (listener change myValue to 'default' and so object result unmodified to db), flush and exit from transaction (so is committed). After that i find version=2 on my object, but version=1 on db.
Is that an hibernate bug? Or a Jpa bug?