4 Replies Latest reply on Oct 15, 2010 3:06 AM by Adam Warski

    Auditing table with @EmbeddedId and @ManyToOne?

    Alex K Newbie

      I'm trying to audit a table that has a composite primary key with a many-to-one relation, and I'm getting "Type not supported: org.hibernate.type.ManyToOne".

       

      Seems to be the same issue as this one: https://jira.jboss.org/browse/ENVERS-76

       

      Is there a fix for this, or should I expect one? If not, could someone suggest the best way to work around this?

       

      I'm using Hibernate 3.5.1-Final.

       

      The entities look like this:

       

      // EntityA.java

      @Entity
      @Table(name = "table_a")
      public class EntityA {

       

          @Id
          @Audited
          @Column(name = "entity_a_id", nullable = false, updatable = false)
          private Long id;

       

          ...

       

          @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
          @OneToMany(mappedBy = "entity_a", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
          private Set<EntityB> entityBs = new HashSet<EntityB>();
      }

       

      // EntityB.java

      @Entity
      @Table(name = "entity_b")
      public class EntityB {

       

          @Id
          private EntityBPK id = new EntityBPK();
      ...
      }

       

      // EntityBPK.java

      @Embeddable
      public class EntityBPK {

       

          @ManyToOne
          @JoinColumn(name = "entity_a_id")
          private EntityA entityA;

       

          @Column(name = "extra_id", nullable = false)
          private String extraId;
      ...
      }

       

      Exception:

       

      Caused by: org.hibernate.HibernateException: could not init listeners
              at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:205)
              at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1396)
              at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1385)
              at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)
              at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
              ... 45 more
      Caused by: org.hibernate.MappingException: Type not supported: org.hibernate.type.ManyToOneType
              at org.hibernate.envers.configuration.metadata.IdMetadataGenerator.addIdProperties(IdMetadataGenerator.java:75)
              at org.hibernate.envers.configuration.metadata.IdMetadataGenerator.addId(IdMetadataGenerator.java:120)
              at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:374)
              at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:100)
              at org.hibernate.envers.configuration.AuditConfiguration.<init>(AuditConfiguration.java:86)
              at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:99)
              at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:315)
              at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
              at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
              at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)

       

      Thanks,

      Alex