1 Reply Latest reply on Mar 12, 2015 2:48 AM by klv_m72

    Hibernate exception while processing a Mappedsuperclass with @version

    sai.krish

      I have a create a simple test program with 3 classes namely BaseEntity.java (with @Mappedsuperclass annotation) - which contains just one attribute namely "version". It has two extended classes Customer and Season - having few fields. When I deploy this ejbModule in JBoss 7.1.1 Final release I get a NullPointerException from Hibernate's AttributeFactory as given below

       

      00:03:13,348 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-9) MSC00001: Failed to start service jboss.persistenceunit."Test.jar#primary": org.jboss.msc.service.StartException in service jboss.persistenceunit."Test.jar#primary": Failed to start service

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_05]

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_05]

                at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_05]

      Caused by: java.lang.NullPointerException

                at org.hibernate.ejb.metamodel.AttributeFactory$6.resolveMember(AttributeFactory.java:947)

                at org.hibernate.ejb.metamodel.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:423)

                at org.hibernate.ejb.metamodel.AttributeFactory.buildVersionAttribute(AttributeFactory.java:153)

                at org.hibernate.ejb.metamodel.MetadataContext.applyVersionAttribute(MetadataContext.java:301)

                at org.hibernate.ejb.metamodel.MetadataContext.wrapUp(MetadataContext.java:206)

                at org.hibernate.ejb.metamodel.MetamodelImpl.buildMetamodel(MetamodelImpl.java:64)

                at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:91)

                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)

                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)

                at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)

                at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)

                at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

       

      When I removed the class Season the test application is deployed properly. I tried turning on the log level to TRACE for hiberate, but I could not trace the actual reason for the EntityMetamodel being null.

       

      All the relevant files including the Entities, db creation script for mysql are attached.

       

      Thanks,

      SK

        • 1. Re: Hibernate exception while processing a Mappedsuperclass with @version
          klv_m72

          It is probably to late for you, but it might save other people a lot of time.

           

          The reason for this error is: you are mixing property and field based access:

          Your BaseEntity has:

           

          @Version

          private int version;

           

          Customer class matches BaseEntity: it also has annotations on fields:

          @Id

          @Column(nullable = false)

          @GeneratedValue(strategy = GenerationType.IDENTITY)

          private int customerid;

           

           

          But Season has annotations on getters:

          @Id

          @Column(nullable = false)

          @GeneratedValue

          public int getSeasonid()

          { return seasonid; }

           

           

          A not that obvious thing about this is that the application might sometimes work OK and sometimes fail.

          1 of 1 people found this helpful