I'm using JPA Toplink Essential, Netbean6.8, GlassFish v3
In my Entity class I added @Version annotation
to enable optimistic locking
at transaction commit however after I added the annotation, my query started including VERSION as column thus throwing SQL exception.
None of this is mentioned in any tutorial I've seen so far. What could be wrong?
Snippet
public class MasatosanTest2 implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Column(name = "username")
private St开发者_运维技巧ring username;
@Column(name = "note")
private String note;
//here adding Version
@Version
int version;
query used:
SELECT m FROM MasatosanTest2 m
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException
Call: SELECT id, username, note, VERSION FROM MasatosanTest2
You should add version as numeric column to your table. This column will be used for optimistic locking.
But I do prefer date field for optimistic locking, in that way you can track when that object has changed.
精彩评论