Hibernate version: 3.2.5.GA with em 3.3.1.GA
This is the base class for our persistent objects:
Code:
/**
* Base class for persistent objects.
*
* @actionscript.class bindable=true
*/
@MappedSuperclass
public abstract class EntityObject implements Serializable {
@Id
@GeneratedValue
private long id;
@Version
@Column(nullable = false)
private Long version;
[...]
}
when calling em.merge(object) the version property is not incremented in the entity object (it is in the database), hence when i reuse and merge the same object a second time i get an optimistic locking exception. even worse, if i try to reload the object after merging via refresh and find, i still get the object with the old version id.
i stepped through the code and it seems, that the copy of the entity, that is put into the session cache, is made before the fields are updated with the values from the database.
maybe related to this issue is a mysql issue with timestamp version properties. mysql only has a granularity of seconds for timestamps, hence the version timestamp gets truncated when the object is persisted into the database. since the resulting truncated value is never updated in the entity any further operation fails.
can this be considered to be a bug in the entity manager or am i doing something wrong?