-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Issues with Version Column for Optimistic Locking
PostPosted: Wed Oct 03, 2007 5:24 pm 
Newbie

Joined: Tue Sep 25, 2007 11:37 am
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 05, 2007 12:15 pm 
Newbie

Joined: Wed Aug 29, 2007 3:28 pm
Posts: 2
Location: Atlanta, GA
You need to annotate Persistent with @MappedSuperclass.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.