2 Replies Latest reply on Mar 4, 2013 9:40 PM by Guillaume Humbert

    Envers not working with <dynamic-component> mapping?

    Guillaume Humbert Newbie

      Hi!

       

      I am trying to use Envers in our software, but a NullPointerException is thrown on startup.

       

      After a few time of debugging, it seems to be because of the <dynamic-component> mappings that we have for some entities.

       

      Is there any proper way to deal with this?

       

      The only quick and dirty way that I found is to replace some code in the EntitiesConfigurator class.

      Hopefully I do not need to audit the classes mapped with some dynamic components.

       

      Original code:

       

           while (classes.hasNext()) {
                  PersistentClass pc = classes.next();
      
      
                  // Collecting information from annotations on the persistent class pc
                  AnnotationsMetadataReader annotationsMetadataReader =
                          new AnnotationsMetadataReader(globalCfg, reflectionManager, pc);
                  ClassAuditingData auditData = annotationsMetadataReader.getAuditData();
      
      
                  classesAuditingData.addClassAuditingData(pc, auditData);
              }
      

       

       

      Modified code:

       

       

          while (classes.hasNext()) {
                  PersistentClass pc = classes.next();
      
      
                  // Collecting information from annotations on the persistent class pc
                  AnnotationsMetadataReader annotationsMetadataReader =
                          new AnnotationsMetadataReader(globalCfg, reflectionManager, pc);
      
                  if (annotationsMetadataReader == null) {
                     continue;
                  }
      
                  ClassAuditingData auditData = annotationsMetadataReader.getAuditData();
      
      
                  classesAuditingData.addClassAuditingData(pc, auditData);
              }
      

       

       

      Stack trace:

       

      Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tcmTxManager' defined in class path resource [context.xml]: Cannot resolve reference to bean 'tcmSessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tcmSessionFactory' defined in class path resource [context.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException

                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)

                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1391)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1132)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)

                at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)

                at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)

                at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)

                at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

                at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)

                at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)

                at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)

                at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

                at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)

                at org.acn.testproject.Main.main(Main.java:16)

      Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tcmSessionFactory' defined in class path resource [context.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)

                at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)

                at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)

                at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)

                at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

                at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:323)

                ... 15 more

      Caused by: java.lang.NullPointerException

                at java.lang.Class.forName0(Native Method)

                at java.lang.Class.forName(Class.java:247)

                at org.hibernate.annotations.common.util.ReflectHelper.classForName(ReflectHelper.java:143)

                at org.hibernate.annotations.common.reflection.java.JavaReflectionManager.classForName(JavaReflectionManager.java:117)

                at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader$ComponentPropertiesSource.<init>(AuditedPropertiesReader.java:549)

                at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader$ComponentPropertiesSource.<init>(AuditedPropertiesReader.java:543)

                at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.addFromComponentProperty(AuditedPropertiesReader.java:340)

                at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.addFromProperties(AuditedPropertiesReader.java:296)

                at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.addPropertiesFromClass(AuditedPropertiesReader.java:277)

                at org.hibernate.envers.configuration.metadata.reader.AuditedPropertiesReader.read(AuditedPropertiesReader.java:103)

                at org.hibernate.envers.configuration.metadata.reader.AnnotationsMetadataReader.getAuditData(AnnotationsMetadataReader.java:114)

                at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:79)

                at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:113)

                at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:165)

                at org.hibernate.envers.event.EnversIntegrator.integrate(EnversIntegrator.java:64)

                at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:303)

                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750)

                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1788)

                at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)

                at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)

                at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)

                at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)

                ... 22 more