1 Reply Latest reply on Aug 28, 2008 3:16 AM by adamw

    versioning of one-to-many (on the owning side) bi-directiona

    twisgabak

      Hi Adam,

      According to the Envers project page, I was under the impression that one-to-many relations were supported, but I cant get it working with a simple test case.

      I have 2 classes that I wrote to test Envers versioning. Without versioning, the mapping is working as expected with hibernate. Adding the @Versioned annotation to my collection attribute throws an exception.

      Here is the annotated code causing the exception:

      
      @Entity(name = "Car")
      @Table(name = "CAR")
      public class Car
      {
      @Column(name = "DRIVERS")
      @OneToMany
      @JoinTable(name = "CAR_DRIVERS", joinColumns = { @JoinColumn(name = "CAR_ID") }, inverseJoinColumns = { @JoinColumn(name = "PERSON_ID") })
      private Set<Person> drivers = new HashSet<Person>(0);
      
      /* ... */
      
      }
      
      @Entity(name = "Person")
      @Table(name = "PERSON")
      public class Person
      {
      /* ... */
      }
      
      


      Here is the exception message:

      [...]
      org.hibernate.MappingException: Type not supported for versioning: org.hibernate.type.SetType, on entity Car, property 'drivers'.
      at org.jboss.envers.metadata.VersionsMetadataGenerator.addProperties(VersionMetadataGenerator.java:399)
      [...]
      



      I tried with other collection types (lists, bags) and I always get the same type of error. I also saw some feature/bugfix request related to OneToMany mapping so I was wondering if the support was available in the version I am using (1.0.0.ga)? If so, any idea what I'm doing wrong? What would be the right way to achieve this simple OneToMany relation within Envers?

      Finally, do you have development snapshots more recent than the one posted on 2008/07/16? or automated nightlybuilds that I could get copy of?


      Thanks in advance!

        • 1. Re: versioning of one-to-many (on the owning side) bi-direct
          adamw

          Hello,

          when, you've hit the one case that doesn't yet work :)

          In Envers 1.0.0.GA, a lonely @ManyToOne and a combination of @ManyToOne and @OneToMany(mappedBy="") will work.

          In the current trunk version, a lonely @OneToMany or @OneToMany+@JoinTable will additionally work.

          There is still the case of @OneToMany+@JoinColumn (see https://jira.jboss.org/jira/browse/ENVERS-26), which I'm working on resolving right now.

          The problem here is that if you use @OneToMany or @OneToMany+@JoinTable, Hibernate (and Envers) generates a third table to store the relation data. Now, if you use @OneToMany+@JoinColumn, the foreign key is stored in the entity, to which the relation referes to (so the database mapping is identical to the one generated when using @ManyToOne or @ManyToOne+@OneToMany(mappedBy=""), however the owning side of the relation is different, which has effects on how you can use the collection).

          I've uploaded the latest jars to the development section.

          --
          Adam