2 Replies Latest reply on Oct 17, 2008 10:23 AM by Scott Robidoux

    Envers1.1 and ManyToMany

    Scott Robidoux Newbie

      Using Jboss 4.3 with Envers 1.1

      I have two classes, a Request class and an Equipment class. The Request class has an attribute

      List<Equipment> equipment
      that has a unidirectional ManyToMany relationship.

      When trying to generate ddl through Ant using the org.hibernate.tool.ant.EnversHibernateToolTask, the following error is thrown:

      BUILD FAILED
      C:\Workspace\MyEclipse 6.0\Equipment Request - EJB\build.xml:118: org.hibernate.MappingException: Type not supported for versioning: org.hibernate.type.BagType, on entity equipreq.jpa.Request, property 'equipment'.
      at org.hibernate.tool.ant.HibernateToolTask.reportException(HibernateToolTask.java:226)
      at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:189)
      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
      at org.apache.tools.ant.Task.perform(Task.java:348)
      at org.apache.tools.ant.Target.execute(Target.java:357)
      at org.apache.tools.ant.Target.performTasks(Target.java:385)
      at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
      at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
      at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
      at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
      at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
      Caused by: org.hibernate.MappingException: Type not supported for versioning: org.hibernate.type.BagType, on entity equipreq.jpa.Request, property 'equipment'.
      at org.jboss.envers.metadata.VersionsMetadataGenerator.addProperties(VersionsMetadataGenerator.java:399)
      at org.jboss.envers.metadata.VersionsMetadataGenerator.generateFirstPass(VersionsMetadataGenerator.java:589)
      at org.jboss.envers.configuration.VersionsConfiguration.configure(VersionsConfiguration.java:150)
      at org.jboss.envers.configuration.VersionsConfiguration.getFor(VersionsConfiguration.java:238)
      at org.jboss.envers.ant.JPAConfigurationTaskWithEnvers.doConfiguration(JPAConfigurationTaskWithEnvers.java:33)
      at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
      at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:302)
      at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:45)
      at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:186)
      ... 16 more

      Any ideas what is happening here? The only information I can get out of this is, when looking at the Bag class of Hibernate, this is given as the javadoc class description:

      A bag permits duplicates, so it has no primary key

      Thanks for any help or direction you can give. :-)

      Scott

        • 1. Re: Envers1.1 and ManyToMany
          Adam Warski Master

          Hello,

          are you sure you are using Envers 1.1 (beta2 is the newest version)? Because the VersionsMetadataGenerator is only 381 lines long - and your exception is thrown at line 399. I think it should work with beta2.

          However, if you want to store duplicates in your list you'll experience run-time errors (see: http://www.jboss.org/envers/collections.html). This is because when storing duplicates in a list (with an index annotation), you will get duplicate rows in the relation table - so it's not possible to create a primary key. There are several solutions to this problem:
          - if you won't have duplicates, then you won't have problems
          - use a Set (you also won't have duplicates then :) )
          - use an indexed collection (then, additionally to the elements, you have an index-in-the-list column, so creating a primary key is possible)

          --
          Adam

          • 2. Re: Envers1.1 and ManyToMany
            Scott Robidoux Newbie

            Hi Adam,

            Thanks for the quick response.

            You were correct, this was an id10t error on my part. :-) I had the Enverse 1.1 beta 2 on the project build path, but forgot to update the library dependency in the build.properties file from 1.0 GA. After I updated the library dependency, the ddl was created correctly. This was probably also the reason why, when I switched the list to a Set yesterday, I was getting the TypeNotSupported error.

            As I said, I have updated the build.properties file to Envers 1.1 beta2 and changed the list to a set and the ddl is created without error.

            Thanks for the help!