1 Reply Latest reply on Apr 3, 2018 7:13 AM by Klaus Gradinger

    Envers 5.2.11 NullPointerException in IdMetadataGenerator

    John Casebolt Newbie

      Hi All!

       

      Just bumped my HIbernate dependencies up to version 5.2.11 this morning, and I am now seeing an NPE when initializing (code was unchanged):

       

      Caused by: java.lang.NullPointerException: null

        at org.hibernate.envers.configuration.internal.metadata.IdMetadataGenerator.generateSecondPass(IdMetadataGenerator.java:115)

        at org.hibernate.envers.configuration.internal.metadata.IdMetadataGenerator.generateSecondPass(IdMetadataGenerator.java:102)

        at org.hibernate.envers.configuration.internal.metadata.AuditMetadataGenerator.generateSecondPass(AuditMetadataGenerator.java:750)

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

        at org.hibernate.envers.boot.internal.EnversServiceImpl.doInitialize(EnversServiceImpl.java:154)

        at org.hibernate.envers.boot.internal.EnversServiceImpl.initialize(EnversServiceImpl.java:118)

        at org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl.produceAdditionalMappings(AdditionalJaxbMappingProducerImpl.java:99)

        at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:288)

        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858)

        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885)

        at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)

        ... 45 common frames omitted

       

      Here are the annotations on the (unchanged) entity that seems to be the problem:

       

      @Audited
      @Entity
      @Table(name = "user_project", catalog = "cons3rt")
      public class UserProject implements Serializable {
      
      
          /** The Constant serialVersionUID. */
          private static final long serialVersionUID = -1649617134300147133L;
      
      
          /** The pk. */
          @EmbeddedId
          private UserProjectPk pk = new UserProjectPk();
      
      
          /** The roles. */
          @CollectionTable(name = "user_project_role", joinColumns = {
                  @JoinColumn(name = "user_project_user_id", referencedColumnName = "user_id"),
                  @JoinColumn(name = "user_project_project_id", referencedColumnName = "project_id") })
          @Column(name = "role_name")
          @ElementCollection
          @OrderColumn
          @Enumerated(EnumType.STRING)
          private Set<RoleType> roles = new HashSet<>();
      
      
          @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
          @JoinColumn(name = "api_token_id")
          private ApiToken apiToken;
      
      
          @Column(name = "slack_user_id")
          private String slackUserId;
      
      
        ...
        }
      

       

      It looks like quite a bit of code has changed in the IdMetadataGenerator class between 5.2.10 and 5.2.11.

      Stepping through in the debugger, it seems like the EmbeddedId UserProjectPk class is in the entitiesConfigurationMap, but line 115 is trying to pull the class of one of the fields of the composite embedded id out of that map instead of the UserProjectPk class itself.

       

      Was I getting by with something I should not have been up to this point? Or is this a regression?

      More than happy to help debug, file tracker, etc.

       

      Thanks!

      John