3 Replies Latest reply on Sep 24, 2008 1:25 PM by adepue

    NullPointerException in latest svn version

    adepue

      I just built envers from the latest svn, and am getting a NullPointerException when using it in my own project.. note that the latest downloaded beta does not give this exception. Also note that envers passed all its tests.
      I can see why the NullPointerException is happening, but I am not yet familiar enough with Envers source to know what to make of it. Here is the stack trace:

      Caused by: java.lang.NullPointerException
       at org.jboss.envers.configuration.metadata.BasicMetadataGenerator.addComponent(BasicMetadataGenerator.java:132)
       at org.jboss.envers.configuration.metadata.BasicMetadataGenerator.addBasic(BasicMetadataGenerator.java:24)
       at org.jboss.envers.configuration.metadata.CollectionMetadataGenerator.addValueToMiddleTable(CollectionMetadataGenerator.java:308)
       at org.jboss.envers.configuration.metadata.CollectionMetadataGenerator.addWithMiddleTable(CollectionMetadataGenerator.java:225)
       at org.jboss.envers.configuration.metadata.CollectionMetadataGenerator.addCollection(CollectionMetadataGenerator.java:99)
       at org.jboss.envers.configuration.metadata.VersionsMetadataGenerator.addValue(VersionsMetadataGenerator.java:148)
       at org.jboss.envers.configuration.metadata.VersionsMetadataGenerator.addProperties(VersionsMetadataGenerator.java:170)
       at org.jboss.envers.configuration.metadata.VersionsMetadataGenerator.generateSecondPass(VersionsMetadataGenerator.java:341)
       at org.jboss.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:93)
       at org.jboss.envers.configuration.VersionsConfiguration.<init>(VersionsConfiguration.java:80)
       at org.jboss.envers.configuration.VersionsConfiguration.getFor(VersionsConfiguration.java:93)
       at org.jboss.envers.event.VersionsEventListener.initialize(VersionsEventListener.java:192)
       at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:417)
       at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1310)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
       at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
       at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)
       at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)
       at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
       at ... (you get the idea)


      addValueToMiddleTable(...) is invoking BasicMetadataGenerator.addBasic, and the source line is hard coded to pass in null for the 'mapper' parameter, which gets propagated to addComponent. btw, it appears to be working on an @Embedded component, which is itself mapped via @CollectionOfElements. The parent entity maps it like so:

      @CollectionOfElements(fetch= FetchType.EAGER)
       @JoinTable(name="h_type_allowed_child", joinColumns = @JoinColumn(name="parent_type"))
       @IndexColumn(name="pos")
       @Cache(usage=CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
       public List<AllowedChildElement> getAllowedChildTypes()


      The actual element has four properties: two integer, one string, and one @ManyToOne mapped like so:
      @ManyToOne(targetEntity=HRecordTypeImpl.class)
       @JoinColumn(name="child_type")
       @Index(name="idx_ace_child_type")
       public HRecordType<?> getAllowedChild()


      It's no problem if Envers does not yet support this - it would just be nice if it failed in a more elegant way. :)

        • 1. Re: NullPointerException in latest svn version
          adepue

          Here is some more info. I have another property mapped in almost the exact same way (a List of embedded elements) - the only difference being it does not define an @IndexColumn. This particular embedded element defines only two properties, and they are both String. It produces the exact same NullPointerException, so it looks like the @ManyToOne within the other embedded element was not to blame.

          • 2. Re: NullPointerException in latest svn version
            adamw

            Hello,

            well you shouldn't get the NPE with the latest SVN (from yesterday), as the call to addBasic is replaced with addBasicNoComponent, which throws an exception in case of an unsupported type.

            You have in fact hit two issues with your case:
            1. https://jira.jboss.org/jira/browse/ENVERS-51 - adding support for collections of components (unless it's a component that is the key of a map when using JPA's @MapKey)
            2. supporting relations in components - so far I support only JPA-style components (which can contain only "simple" properties). There's not even a JIRA for that, you can create it if you wish :)

            --
            Adam

            • 3. Re: NullPointerException in latest svn version
              adepue

               

              "adamw" wrote:
              ...
              2. supporting relations in components - so far I support only JPA-style components (which can contain only "simple" properties). There's not even a JIRA for that, you can create it if you wish :)
              ...

              I created issue https://jira.jboss.org/jira/browse/ENVERS-53 - a feature request for relations in components. :)