History | Log In     View a printable version of the current page. Get help!  
Issue Details (XML | Word)

Key: JBSEAM-2389
Type: Bug Bug
Status: Open Open
Priority: Critical Critical
Assignee: Unassigned
Reporter: Christian Bauer
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Seam

HibernatePersistenceProvider fails with java.lang.Integer version check

Created: 17/Dec/07 08:41 AM   Updated: 16/May/08 06:35 AM
Component/s: Core
Affects Version/s: None
Fix Version/s: The future

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown


 Description  « Hide
My entity had a version property:

    @Version
    @Column(name = "OBJ_VERSION", nullable = false)
    protected Integer version;

In a very involved ajax reRender/conversation situation I sometimes got the following exception from HibernatePersistenceProvider:

   public static void checkVersion(Object value, Session session, Object oldVersion, Object version)
   {
      ClassMetadata classMetadata = getClassMetadata(value, session);
      VersionType versionType = (VersionType) classMetadata.getPropertyTypes()[ classMetadata.getVersionProperty() ];
      if ( !versionType.isEqual(oldVersion, version) )
      {
         throw new StaleStateException("current database version number does not match passivated version number");
      }
   }

This failed because oldVersion was 'null' and version was '0'.

Hibernate returned '0' from ClassMetaData.getVersion(), it looks like it can't return null, from Javadoc: Get the version number (or timestamp) from the object's version property (or return null if not versioned).

We should do a null check before asking Hibernate.

Workaround: Use primitive for version field in entity or initialize it to '0'.




 All   Comments   Work Log   Change History   Subversion Commits      Sort Order:
Christian Bauer [17/Dec/07 08:45 AM]
I checked if we really recommend using java.lang.Integer as a version property and we actually do in the Hibernate reference:

"Declaring a nullable version or timestamp property is an easy way to avoid any problems with transitive reattachment in Hibernate, especially useful for people using assigned identifiers or composite keys!"


Pete Muir [27/Dec/07 06:29 AM]
I think we need a test for this.

Pete Muir [04/Jan/08 05:59 PM]
Yes, I either need reproduction steps or a test case as I can't see from the code how you can end with oldVersion as null (it's initialized from ClassMetaData.getVersion()).

Pete Muir [09/Jan/08 09:07 AM]
No longer reproducible in wiki.