1 Reply Latest reply on Jun 13, 2006 2:40 PM by tefron

    Optimistic Locking & Versioning

    sdawson

      Hello,

      I've added a @Version annotation to my entity beans, hoping to take advantage of the optimistic locking provided by JBoss. My understanding is that the EntityManager is responsible for incrementing the version number when an object is persisted; is this correct?

      Currently, the EntityManager is not updating the Version property when an object is persisted. The EntityManager is, however, throwing StaleObject exceptions if I manually change the version number on an Entity and then try to persist it.

      Is there extra configuration needed to enable version incrementing when objects are persisted, or is this not possible / supported?

      Thank you,
      Sean Dawson

        • 1. Re: Optimistic Locking & Versioning
          tefron

          it should work fine.
          What you need in your hbm files is:

          .....
          <class name="com.canpay.gm.persistent.model.BankAccount" table="BankAccount" optimistic-lock="version">
          ....
          xxx
          <id name="id" column="id" type="long" unsaved-value="null">


          <natural-id>

          </natural-id>

          ....other properties


          TEFRON