3 Replies Latest reply on Feb 23, 2011 5:15 AM by benoit.heinrich

    @OrderColumn and @AuditMappedBy, MappingException: points to a property that doesn't exist

    benoit.heinrich

      Hi guys,

       

      I'm working on a project where we're using envers and since we're migrating from jboss 4.2.3 to jboss 6.0.0.Final (finally ), I'm then upgrading the old envers to the new one.

      Part of the migration I've changed all the @IndexColumn by the new JPA2 @OrderColumn and it seems that envers doesn't work with that new annotation (or I might do something wrong here )

       

      Also, since we're now using the @OrderColumn the "position" column on the referenced entity has been removed as the hibernate documentation (and JPA2 specs) ask for it.  Since it's been removed I'm getting the problem.

       

      Here is the example mapping:

       

      @Entity

      @Audited

      public class OrganizationEntity {

       

                @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)

                @JoinColumn(name = "org_entity_id", columnDefinition = "int", nullable = false)

                @OrderColumn(name = "position", columnDefinition = "tinyint", nullable = false)

                @AuditMappedBy(mappedBy = "organizationEntity", positionMappedBy = "position")

        private List<OrganizationEntityContactDetail> contactDetailList;

      }

       

      @Entity

      @Audited

      public class OrganizationEntityContactDetail {

        @ManyToOne(fetch = FetchType.EAGER)

                @JoinColumn(name = "org_entity_id", columnDefinition = "int", nullable = false, insertable = false, updatable = false)

                private OrganizationEntity organizationEntity;

      }

       

      Every time I deploy this I'm getting the following error:

      Caused by: org.hibernate.HibernateException: could not init listeners

                at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205) [:3.6.0.Final]

                at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1980) [:3.6.0.Final]

                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842) [:3.6.0.Final]

                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902) [:3.6.0.Final]

                ... 73 more

      Caused by: org.hibernate.MappingException: @AuditMappedBy points to a property that doesn't exist: com.example.services.organization.entity.OrganizationEntityAddress.position

                at org.hibernate.envers.configuration.ClassesAuditingData.forcePropertyInsertable(ClassesAuditingData.java:83)

                at org.hibernate.envers.configuration.ClassesAuditingData.updateCalculatedFields(ClassesAuditingData.java:72)

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

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

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

                at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:335)

                at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198) [:3.6.0.Final]

                at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181) [:3.6.0.Final]

                at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194) [:3.6.0.Final]

                ... 76 more

      I'm doing something wrong here but I'm not sure what.

       

      Do I need to put back the JPA mapping for the "position" column on the referenced entity?

      Do I need to use the positionMappedBy with new @OrderColumn annotation?

       

      If I remove the positionMappedBy then it seems to deploy better, but then the position isn't set in the auditing table.

       

       

      Thanks for helping.

      /Benoit

        • 1. Re: @OrderColumn and @AuditMappedBy, MappingException: points to a property that doesn't exist
          benoit.heinrich

          Actually, I think I've found a working solution which is simply to put back the:

           

             @Column(nullable = false, columnDefinition = "tinyint", updatable = false, insertable = false)

             @SuppressWarnings("unused") // it's just used for the hibernate @IndexColumn in entities referencing list of addresses.

             private Integer position;

           

          and then the mapping deploys and the position is set correctly inside the auditing tables.

           

          Even if it's working I might think it's a workaround and envers should be able to read the column information from the @OrderColumn annotation.

          From the JPA2 specs page 406 or 486

          The OrderColumn annotation is specified on the side of the relationship that references the collection that is to be ordered. The order column is not visible as part of the state of the entity or embeddable class.

           

          Anyway, for now I'm sorted, but let me know if you want me to open a jira bug report.

           

           

          Cheers,

          /Benoit

          • 2. @OrderColumn and @AuditMappedBy, MappingException: points to a property that doesn't exist
            adamw

            Hey,

             

            That's interesting, I didn't yet use the new JPA2 annotations for ordered lists so I didn't event know there was a difference. Please create a bug in JIRA.

             

            The problem is not event getting the column name, but getting the position column value during auditing. But I'm sure there is some way to get it .

             

            Btw. are you also migrating to Seam 3?

             

            Adam

            • 3. Re: @OrderColumn and @AuditMappedBy, MappingException: points to a property that doesn't exist
              benoit.heinrich

              Hey Adam,

               

              Jira bug opened http://opensource.atlassian.com/projects/hibernate/browse/HHH-5955

               

              And to answer the question about Seam 3, yes, we want to upgrade but we're waiting for the final version, same for Richfaces 4.

               

              It's really nice to see how the migration from jboss 4.2.3 to jboss 6.0.0 went very well, we've just started 1 week and half ago and we're nearly done.

              I guess the biggest challenge is to get all integration tests working with Arquillian, but I hope to get that done by end of week

               

               

              Thanks for the answer and talk to you soon I hope

               

              Cheers,

              /Benoit