Hibernate version:3.2.3.ga
Hibernate Annotation version:3.3.0.GA
I'm facing a strange behaviour. I have an versionned entity and one attribute annotated as @OptimisticLock(excluded=true). I'm only changing the attribute wich is excluded from the optimstic lock. Then I try to update it. If I made the change on a persistant instance the version is not incremented at the flush() but if I made the change on a detached object (an object which was in a Session but was evicted from it) and call the update method on a new Session the version is incremented but it shouldn't.
I didn't test it with xml mapping but I would like to know if it's the correct behaviour or a bug?
My entity has several one-to-many relationships and the attribute which is annotated as @OptimisticLock(excluded=true) is also @Embbeded
Code:
@Entity
public class Car {
...
@Id
public Long getId() {
...
@Version
public Long getVersion() {
...
@Embedded
@OptimisticLock(excluded=true)
public Engine getEngine() {
...
...
}
This case doesn't increment the versionCode:
// open session and begin transaction
Car car = session.get(Car.class, id);
car.setEngine(new Engine());
// flush the session
This case increment the version and it should't do itCode:
// open session and begin transaction
Car car = session.get(Car.class, id);
car.setEngine(new Engine());
...
session.evict(car);
...
session.update(car);
// flush the session