JPA optimistic lock - setting @Version to entity class cause query to include VERSION as column

Posted by masato-san on Stack Overflow See other posts from Stack Overflow or by masato-san
Published on 2010-12-28T08:49:12Z Indexed on 2010/12/28 8:54 UTC
Read the original article Hit count: 363

Filed under:
|
|
|
|

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 String 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 

© Stack Overflow or respective owner

Related posts about java

Related posts about jpa