Hi,

I removed the @GeneratedValue
but still no changement.
when updating i don't see any version number.
Is my configuration correct or do I have to put some configurations in the
persistence file.

Greets K,


Craig L Russell wrote:
> 
> Seems like it would be useful for OpenJPA to issue a warning or an  
> error in the case of the user specifying both @Version and  
> @GeneratedValue on the same property.
> 
> Craig
> 
> On Nov 16, 2009, at 9:08 AM, Fay Wang wrote:
> 
>> Hi,
>>   You don't need to put generatedValue annotation for the version  
>> field. Openjpa will keep track of the version for you.
>>
>>  @Version
>>  public long getVersion() {
>>    return this.version;
>>  }
>>
>>
>>
>> ----- Original Message ----
>> From: yokenji <[email protected]>
>> To: [email protected]
>> Sent: Mon, November 16, 2009 8:46:48 AM
>> Subject: @Version annotation
>>
>>
>> Hi there,
>>
>> I trying to use an annotatoin field @version but when updating the  
>> record i
>> don't see any version in the database.
>>
>> Also,
>> Element class:
>>
>> package entities;
>>
>> import java.io.Serializable;
>> import java.util.Set;
>>
>> import javax.annotation.Generated;
>> import javax.persistence.CascadeType;
>> import javax.persistence.Column;
>> import javax.persistence.Entity;
>> import javax.persistence.FetchType;
>> import javax.persistence.GeneratedValue;
>> import javax.persistence.GenerationType;
>> import javax.persistence.Id;
>> import javax.persistence.JoinColumn;
>> import javax.persistence.ManyToOne;
>> import javax.persistence.NamedQueries;
>> import javax.persistence.NamedQuery;
>> import javax.persistence.OneToMany;
>> import javax.persistence.Table;
>> import javax.persistence.Temporal;
>> import javax.persistence.TemporalType;
>> import javax.persistence.Version;
>>
>> import org.apache.openjpa.persistence.jdbc.ForeignKey;
>>
>> /**
>> * @author Ken
>> */
>> @Entity
>> @NamedQueries({
>>    @NamedQuery(name="roots.Element",
>>        query="Select e From Element e" +
>>              " where e.parentElement is null"),
>>    @NamedQuery(name="one.Element",
>>        query="Select e From Element e" +
>>              " where e.dbID = :id")
>> })
>> @Table(name="Element")
>> public class Element implements ElementInterface, Serializable {
>>
>>  private static final long serialVersionUID = 4627343050926103812L;
>>
>>  private String dbID;
>>  private String internID;
>>  private String name;
>>  private String description;
>>  private long   version;
>>
>>  private Set<Property>        properties;
>>  private Element              parentElement;
>>  private Set<Element> childElements;
>>
>>  /**
>>   * This is the default constructor.
>>   */
>>  public Element() {
>>  }
>>
>>  /**
>>   * @see entities.ElementInterface#setDbID(java.lang.String)
>>   */
>>  public void setDbID(String dbID) {
>>    this.dbID = dbID;
>>  }
>>
>>  /**
>>   * @see entities.ElementInterface#getDbID()
>>   */
>>  @Id
>>  @GeneratedValue(strategy = GenerationType.AUTO, generator="uuid-hex")
>>  public String getDbID() {
>>    return this.dbID;
>>  }
>>
>>  /**
>>   * @see entities.ElementInterface#setInternID(java.lang.String)
>>   */
>>  public void setInternID(String internID) {
>>    this.internID = internID;
>>  }
>>
>>  /**
>>   * @see entities.ElementInterface#getInternID()
>>   */
>>  public String getInternID() {
>>    return this.internID;
>>  }
>>
>>
>>  /**
>>   * @see entities.ElementInterface#getName()
>>   */
>>  public String getName() {
>>    return this.name;
>>  }
>>
>>  /**
>>   * @see entities.ElementInterface#setName(java.lang.String)
>>   */
>>  public void setName(String name) {
>>    this.name = name;
>>  }
>>
>>  /**
>>   * @see entities.ElementInterface#setDescription(java.lang.String)
>>   */
>>  public void setDescription(String description) {
>>    this.description = description;
>>  }
>>
>>  /**
>>   * @see entities.ElementInterface#getDescription()
>>   */
>>  public String getDescription() {
>>    return this.description;
>>  }
>>
>>  /**
>>   * @see entities.ElementInterface#setVersion(java.util.Date)
>>   */
>>  private void setVersion(int version) {
>>    this.version = version;
>>  }
>>
>>  /**
>>   * @see entities.ElementInterface#getVersion()
>>   */
>>  @Version
>>  @GeneratedValue(strategy=GenerationType.AUTO)
>>  public long getVersion() {
>>    return this.version;
>>  }
>>
>>  /**
>>   * Set the element properties.
>>   *
>>   * @param Set<Property> properties
>>   */
>>  public void setProperties(Set<Property> properties) {
>>    this.properties = properties;
>>  }
>>
>>  /**
>>   * Get the element properties.
>>   *
>>   * @return Set<Property>
>>   */
>>  @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER,
>> mappedBy="element")
>>  public Set<Property> getProperties() {
>>    return properties;
>>  }
>>
>>  /**
>>   * Set the element parent.
>>   *
>>   * @param Element parentElement
>>   */
>>  public void setParentElement(Element parentElement) {
>>    this.parentElement = parentElement;
>>  }
>>
>>  /**
>>   * Get the element parent.
>>   *
>>   * @return Element
>>   */
>>  @ManyToOne(optional=true, fetch=FetchType.LAZY)
>>  @ForeignKey(name="FK_parent_element")
>>  @JoinColumn(name="parent_element", referencedColumnName="dbID")
>>  public Element getParentElement() {
>>    return parentElement;
>>  }
>>
>>  /**
>>   * Set the element children.
>>   *
>>   * @param Set<Element> childElements
>>   */
>>  public void setChildElements(Set<Element> childElements) {
>>    this.childElements = childElements;
>>  }
>>
>>  /**
>>   * Get the element children.
>>   *
>>   * @return Set<Element>
>>   */
>>  @OneToMany(cascade=CascadeType.ALL, mappedBy="parentElement",
>> fetch=FetchType.EAGER)
>>  public Set<Element> getChildElements() {
>>    return childElements;
>>  }
>>
>> }
>>
>> Class Property:
>>
>>
>> package entities;
>>
>> import java.io.Serializable;
>> import javax.persistence.*;
>> import org.apache.openjpa.persistence.jdbc.ForeignKey;
>>
>> /**
>> * @author Ken
>> */
>> @Entity
>> @NamedQueries({
>>  @NamedQuery(name="all.properties",
>>      query="Select p From Property p"),
>>  @NamedQuery(name="elementTemplate.properties",
>>      query="Select p From Property p" +
>>            " where p.elementTemplate = :owner"),
>>  @NamedQuery(name="one.property",
>>      query="Select p From Property p" +
>>            " where p.dbID = :id")
>> })
>> @Table(name="Property")
>> public class Property implements Serializable {
>>
>>  private static final long serialVersionUID = -6988886476498387460L;
>>
>>  private String          dbID;
>>  private String          property;
>>  private String          value;
>>  private Element         element;
>>  private ElementTemplate elementTemplate;
>>
>>  /**
>>   * This is the default constructor.
>>   */
>>  public Property() {
>>  }
>>
>>  /**
>>   * Set the property dbID.
>>   *
>>   * @param String dbID
>>   */
>>  public void setDbID(String dbID) {
>>    this.dbID = dbID;
>>  }
>>
>>  /**
>>   * Get the property dbID.
>>   *
>>   * @return
>>   */
>>  @Id
>>  @GeneratedValue(strategy=GenerationType.AUTO, generator="uuid-hex")
>>  public String getDbID() {
>>    return this.dbID;
>>  }
>>
>>  /**
>>   * Set the property property
>>   *
>>   * @param String property
>>   */
>>  public void setProperty(String property) {
>>    this.property = property;
>>  }
>>
>>  /**
>>   * Get the property property.
>>   *
>>   * @return String
>>   */
>>  public String getProperty() {
>>    return property;
>>  }
>>
>>  /**
>>   * Set the property value.
>>   *
>>   * @param String value
>>   */
>>  public void setValue(String value) {
>>    this.value = value;
>>  }
>>
>>  /**
>>   * Get the property value.
>>   *
>>   * @return String
>>   */
>>  public String getValue() {
>>    return value;
>>  }
>>
>>  /**
>>   * Set property element.
>>   *
>>   * @param Element element
>>   */
>>  public void setElement(Element element) {
>>    this.element = element;
>>  }
>>
>>  /**
>>   * Get the property element.
>>   *
>>   * @return Element
>>   */
>>  @ManyToOne(fetch=FetchType.LAZY)
>>  @ForeignKey(name="FK_property_element")
>>  @JoinColumn(name="element")
>>  public Element getElement() {
>>    return element;
>>  }
>>
>>  /**
>>   * Set the property elementTemplate.
>>   *
>>   * @param ElementTemplate elementTemplate
>>   */
>>  public void setElementTemplate(ElementTemplate elementTemplate) {
>>    this.elementTemplate = elementTemplate;
>>  }
>>
>>  /**
>>   * Get the property elementTemplate.
>>   *
>>   * @return ElementTemplate
>>   */
>>  @ManyToOne(fetch=FetchType.LAZY)
>>  @ForeignKey(name="FK_property_elementTemplate")
>>  @JoinColumn(name="elementTemplate")
>>  public ElementTemplate getElementTemplate() {
>>    return elementTemplate;
>>  }
>>
>> }
>>
>> to update the element I do this:
>> Element element = em.find(Element.class, elementID);
>>
>> //Add changements to the element
>>
>>
>> // update the element.
>> em.persist(element);
>>
>> The update worked but I don't see any version number in my database  
>> field.
>>
>> Please help :)
>>
>>
>> -- 
>> View this message in context:
>> http://n2.nabble.com/Version-annotation-tp4013067p4013067.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>>
>>
>>
> 
> Craig L Russell
> Architect, Sun Java Enterprise System http://db.apache.org/jdo
> 408 276-5638 mailto:[email protected]
> P.S. A good JDO? O, Gasp!
> 
> 
>  
> 

-- 
View this message in context: 
http://n2.nabble.com/Version-annotation-tp4013067p4017236.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to