Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6893749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:41:51+00:00 2026-05-27T06:41:51+00:00

According to the JPA 2.0 specification: The version attribute is updated by the persistence

  • 0

According to the JPA 2.0 specification:

The version attribute is updated by the persistence provider runtime
when the object is written to the database. All non-relationship
fields and properties and all relationships owned by the entity are
included in version checks.

This doesn’t seem to work in my case. I have two Entities:

@Entity
public class OrderedItem {

    @Id
    @GeneratedValue
    private int id;

    private String name;

    @ManyToOne
    private Customer owner;

    @Version
    private int version;

    public OrderedItem(String name) {
        this.name = name;
    }

    // default constructor + bunch of simple accessors and mutators
}

@Entity
public class Customer {

    @Id
    @GeneratedValue
    private int id;

    private String name;

    @OneToMany(mappedBy = "owner")
    private Set<OrderedItem> orderedItems = new HashSet<OrderedItem>();;

    @Version
    private int version;


    public Customer(String name) {
        this.name = name;
    }

    // default constructor + bunch of simple accessors and mutators
}

The “many” side of ManyToOne relationship must be an owning side, so in my case the OrderedItem is the owning side. Following the JPA 2.0 spec, I assume that when I change the Customer object accessed from OrderedItem the version of OrderedItem entity should be incremented. Therefore, I’ve tried to test it:

Customer john = new Customer("John");
OrderedItem milk = new OrderedItem("Milk");

milk.setOwner(john);
john.getOrderedItems().add(milk);

startTx();

em.persist(john);
em.persist(milk);

stopTx();

startTx();

OrderedItem milkFromPC = em.find(OrderedItem.class, milk.getId());
milkFromPC.getOwner().setName("Michael");

stopTx();

The version numbers are 1 for OrderedItem (so no increment) and 2 for Customer.

Any ideas why?


It just bumped into my head while writing this question – is it possible that the “relationship” word in JPA 2.0 specification means that only if I change the entity — Customer — itself (not its state) the version will be incremented? Just like in case of @JoinColumn(updatable=false)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:41:52+00:00Added an answer on May 27, 2026 at 6:41 am

    Yes, as I understand it the version field of OrderedItem will change, if you reassign a different Customer, but not if you change a property of the customer.

    On the other hand, if you add another OrderedItem to the OrderedItem set of the Customer, the version field of the Customer doesn’t get updated because it’s not the owning side.

    I guess it’s useful here to think here in table rows: if any column in a table row changes the version column of that table row gets incremented.

    It’s fine if one client updates the name of the OrderedItem and another the name of the Customer – these updates don’t conflict.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to the answers to this question, I cannot embed a file version in
According to this article Silverlight 2 Beta 2 supports the DataContractJsonSerializer object. But, when
According to the dataset specification , how is element.dataset meant to delete data attributes?
According To reflector , ExpandoObject Does implemenet IDictionary<string, object> How ever I have this
I'm using JPA and I am using second-level cache for all the reference entities.
According to the tutorial : http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=27hibernateloadvshibernateget , If you initialize a JavaBean instance with
I developed app using JPA Toplink which uses JPQL. According to my research JPA
I am using Hibernate (JPA) with Derby database - my app server is Jboss
According to this discussion , the iphone agreement says that it doesn't allow loading
According to the manual , git dcommit will create a revision in SVN for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.