Reputation: 419
I have a base entity class
where one of the fields(Timestamp) has @version attribute, so Jpa will automatically increment the value.
But, sometimes the timestamp value is not getting updated, the edited date is less than the created date, but this should never happen theoretically.
I am not setting the edited value programmatically.
Here is my entity class:
public class BaseEntity implements Serializable {
@Column(name = "CREATED")
private Timestamp created;
@Column(name = "EDITED")
@Version
private Timestamp edited;
// other fields, getters and setters
}
Have read many articles about this @version annotation, but I don't understand why this value will not update, what are the reasons behind this.
If some one help me, would be great
Thanks
Upvotes: 0
Views: 1239
Reputation: 628
Here are some basic guidelines:
javax.persistence.Version
.obj = entityManager.merge(obj);
when saving changes to already persisted entities.For further debugging edit your persitence.xml
and add following lines to properties:
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
<property name="eclipselink.logging.sql.level" value="FINE"/>
This will enable fine logging and generate a lot of output. You'll be able to see the update queries and what exactly happens.
Upvotes: 3