I have a Person class which extends Persistent. Version field is defined inside Persistent class. When I save/update a person object in this setup the version field is not being used at all. If I move the version field to Person class, then it seems to work.
************************************
public abstract class Persistent implements Serializable {
@Column(name="version")
@Version
private int version;
public void setVersion(int version) { this.version = version;}
public int getVersion() { return this.version; }
}
@Entity
@Table(name="person")
@SequenceGenerator(name="person_id_seq", sequenceName="na_generic_id_seq")
public class Person extends Persistent {
@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="person_id_seq")
@Column (name = "person_id")
private Long id;
@Column(name="name")
private String name;
// Getters and setters
}
TestCase:
Person person = new Person();
person.setName("Joe");
savedPerson = personDAO.save(person); // Version column in the db defaulted to 0
savedPerson.setName("Bill");
personDAO.save(savedPerson); // I would have expected version column to be updated to 1
***********************************************
Am I doing something wrong? Should the Id field and the Version field be defined in the same class? If so, why?
Thanks
Ravinder
|