Hi, I'm having two problems with @Version mapped in a @MappedSuperClass class.
This is a preview of my AbstractEntiy:
Code:
@MappedSuperclass
public abstract class AbstractEntity<PK extends Serializable> implements Serializable {
@Transient
@Column(name = "id")
public PK getPrimaryKey() {
return primaryKey;
}
@Version
@Column(name = "version", nullable = false)
public int getVersion() {
return version;
}
}
My first problem was that whenever I added the @Version to a field instead of a property, my version number wouldn't be updated at all.
I still don't know why this was happening, but at least I could make it work by adding the annotation to the property instead.
Now, my real problem and perharps a bug? happens when I try to update my Usr class which extends AbstractEntity.
When I use
Usr user = userDao.update(user);
My user is updated correctly in the database, including it's version number. My variable (user) is also update, however the version field remains the same, old number. What could be happening?
Example:
Code:
BEFORE UPDATE:
Database: Version 1, Name: Bruno
Java: Version 1, Name: Bruno
AFTER UPDATE:
Database: Version 2, Name: Bruno Pinto
Java: Version 1, Name: Bruno Pinto