Uploaded image for project: 'Red Hat Fuse'
  1. Red Hat Fuse
  2. ENTESB-4495

Hibernate and Bundle ClassLoaders out of sync on Bundle Refresh

XMLWordPrintable

    • % %
    • Hide

      Using the reproducer outlined for https://issues.jboss.org/browse/ENTESB-4429 to deploy the hibernate project.

      Restart so the bundles end up in a bad state:

      [2680] [Active     ] [GracePeriod     ] [   60] hibernatetx :: CXF Hibernate (1.0.0.SNAPSHOT)
      [2681] [Active     ] [Created     ] [   60] hibernatetx :: Datamodel (1.0.0.SNAPSHOT)
      [2682] [Active     ] [Created     ] [   60] hibernatetx :: XA-Datasource (1.0.0.SNAPSHOT)
      

      Refresh the datamodel bundle

      Fabric8:admin@fuse-services2> osgi:refresh 2681
      

      Insert a record into the DB:

      insert into person (ID,ADDEDBY,ADDEDON,COUNTRY,FIRSTNAME,LASTCHANGEDBY,LASTCHANGEDDATE,LASTNAME,VERSION) values (1,'Admin',CURRENT_TIMESTAMP,'Canada','Matt','Admin',CURRENT_TIMESTAMP,'Robson',0);
      
      insert into addresses (ID,ADDEDBY,ADDEDON,LASTCHANGEDBY,LASTCHANGEDDATE,VERSION,CITY,PERSON_ID) values (1,'Admin',CURRENT_TIMESTAMP,'Admin',CURRENT_TIMESTAMP,0,'Toronto',1);
      
      commit;
      

      Do a get request on person 1

      http://host:8181/cxf/hibernatetx/person/findById/1
      

      Get CCE

      Caused by: java.lang.ClassCastException: org.mrobson.example.hibernatetx.datamodel.Person cannot be cast to org.mrobson.example.hibernatetx.datamodel.Person
      	at org.mrobson.example.hibernatetx.cxfhibernate.persistence.dao.BaseDao.getPersonById(BaseDao.java:50)
      	at Proxyfe539671_00a8_4ef1_bf99_1f1e42852ae9.getPersonById(Unknown Source)
      
      Show
      Using the reproducer outlined for https://issues.jboss.org/browse/ENTESB-4429 to deploy the hibernate project. Restart so the bundles end up in a bad state: [2680] [Active ] [GracePeriod ] [ 60] hibernatetx :: CXF Hibernate (1.0.0.SNAPSHOT) [2681] [Active ] [Created ] [ 60] hibernatetx :: Datamodel (1.0.0.SNAPSHOT) [2682] [Active ] [Created ] [ 60] hibernatetx :: XA-Datasource (1.0.0.SNAPSHOT) Refresh the datamodel bundle Fabric8:admin@fuse-services2> osgi:refresh 2681 Insert a record into the DB: insert into person (ID,ADDEDBY,ADDEDON,COUNTRY,FIRSTNAME,LASTCHANGEDBY,LASTCHANGEDDATE,LASTNAME,VERSION) values (1, 'Admin' ,CURRENT_TIMESTAMP, 'Canada' , 'Matt' , 'Admin' ,CURRENT_TIMESTAMP, 'Robson' ,0); insert into addresses (ID,ADDEDBY,ADDEDON,LASTCHANGEDBY,LASTCHANGEDDATE,VERSION,CITY,PERSON_ID) values (1, 'Admin' ,CURRENT_TIMESTAMP, 'Admin' ,CURRENT_TIMESTAMP,0, 'Toronto' ,1); commit; Do a get request on person 1 http: //host:8181/cxf/hibernatetx/person/findById/1 Get CCE Caused by: java.lang.ClassCastException: org.mrobson.example.hibernatetx.datamodel.Person cannot be cast to org.mrobson.example.hibernatetx.datamodel.Person at org.mrobson.example.hibernatetx.cxfhibernate.persistence.dao.BaseDao.getPersonById(BaseDao.java:50) at Proxyfe539671_00a8_4ef1_bf99_1f1e42852ae9.getPersonById(Unknown Source)
    • 6.3 Sprint 4 (Mar 28 - Apr 29)

      Using Fuse 6.1 which ships Hibernate 4.2.9.Final, there is an issue with certain bundle refreshes and deployments that manifests in 2 ways.

      CCE on finds

      Caused by: java.lang.ClassCastException: org.mrobson.example.minihibernate.datamodel.Person cannot be cast to org.mrobson.example.minihibernate.datamodel.Person
      

      PropertyAccessException on merges

      Cause: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of org.mrobson.example.minihibernate.datamodel.Person.id Error: IllegalArgumentException: Can not set int field org.mrobson.example.minihibernate.datamodel.Person.id to org.mrobson.example.minihibernate.datamodel.Person
      

      Attached are 3 screenshots from the heapdump.

      person_bundleCL_osgiCL_CCE.png shows the Person class from BundleClassLoader 0xe1ce0250 mapped to the Hibernate OsgiClassLoader.

      Drilling down on the OsgiClassLoader, it's referencing the old BundleClassLoader which has an out of date reference to a Person class object that no longer maps to the datamodel bundles ClassLoader.

      person_bundleREV_bundleCL_CCE.png shows my datamodel bundle with it's Person class in BundleClassLoader 0xe22d9420 thus putting the parent and sub enhanced class within different classloaders as well as being incorrectly mapped to the OsgiClassLoader.

      person_bundleREV_buncleCL_Working.png shows restarting again to bring things into a working state.

      OsgiClassLoader references BundleClassLoader 0xf7c89828 which maps to both Person from datamodel and the enhanced Person class.

      It looks like in this case Hibernate is not re-creating the OSGI classloader mappings with updated references when certain combinations of bundle restarts or deployments happen with the bundle containing the entity classes. From there, it's references end up out of date.

        1. person_bundleCL_osgiCL_CCE.png
          288 kB
          Matt Robson
        2. person_bundleREV_buncleCL_Working.png
          226 kB
          Matt Robson
        3. person_bundleREV_bundleCL_CCE.png
          757 kB
          Matt Robson
        4. UnknownServiceError.txt
          66 kB
          Torsten Mielke

              ggrzybek Grzegorz Grzybek
              rhn-support-mrobson Matt Robson
              Tomas Turek Tomas Turek
              Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

                Created:
                Updated:
                Resolved: