5 Replies Latest reply on Apr 1, 2009 2:24 PM by adamw

    Problem generating schema from ant

      Hello,
      I am trying to generate the schema for my DB from an ant task using EnversHibernateToolTask. I have only one class marked as "Audited" and I am getting an exception. When I remove the annotation "Audited" the schema generation works fine. The class has no related entities and but inherits from an abstract class that also has only simple data fields.

      Here is the exception:

      java.lang.NullPointerException
      at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateInheritanceMappingData(AuditMetadataGenerator.java:285)
      at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateFirstPass(AuditMetadataGenerator.java:344)
      at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:87)
      at org.hibernate.envers.configuration.AuditConfiguration.(AuditConfiguration.java:86)
      at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:99)
      at org.hibernate.envers.ant.JPAConfigurationTaskWithEnvers.doConfiguration(JPAConfigurationTaskWithEnvers.java:36)
      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)
      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
      at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      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)


      Any help would be appreciated.

      Thanks,
      Brocha

        • 1. Re: Problem generating schema from ant
          adamw

          Hello,

          can you post your mappings? Maybe (just a though, not sure about this), if you have a subclass that is @Audited, but the superclass is not? (and both sub- and super-classes are entities)

          Adam

          • 2. Re: Problem generating schema from ant

            Thanks, that was exactly the issue.

            Now I am having a different problem. I have 2 entites that have a oneToMany relationship and have a bi-directional definition with a join table and envers doesn't like it.

            class Person{

            private int personID;

            @OneToMany(mappedBy = "personAtAddress")
            private Set addresses = new HashSet();
            }

            class Address{
            private int addressID;

            @ManyToOne
            @JoinTable(name = "PersonAddress",
            joinColumns = {
            @JoinColumn(name = "addressID", unique = true)},
            inverseJoinColumns = {@JoinColumn(name = "personID")}
            )
            private Person personAtAddress;

            }

            I get the following error:

            [hibernatetool] org.hibernate.MappingException: Unable to read the mapped by attribute for addresses in com.xconnect.peering.registry.Person!
            org.hibernate.MappingException: Unable to read the mapped by attribute for vobbRoles in com.xconnect.peering.registry.Person!
            at org.hibernate.envers.configuration.metadata.CollectionMetadataGenerator.getMappedBy(CollectionMetadataGenerator.java:520)
            at org.hibernate.envers.configuration.metadata.CollectionMetadataGenerator.addWithMiddleTable(CollectionMetadataGenerator.java:272)
            at org.hibernate.envers.configuration.metadata.CollectionMetadataGenerator.addCollection(CollectionMetadataGenerator.java:153)
            at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.addValue(AuditMetadataGenerator.java:141)
            at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.addProperties(AuditMetadataGenerator.java:161)
            at org.hibernate.envers.configuration.metadata.AuditMetadataGenerator.generateSecondPass(AuditMetadataGenerator.java:385)
            at org.hibernate.envers.configuration.EntitiesConfigurator.configure(EntitiesConfigurator.java:96)
            at org.hibernate.envers.configuration.AuditConfiguration.(AuditConfiguration.java:86)
            at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:99)
            at org.hibernate.envers.ant.JPAConfigurationTaskWithEnvers.doConfiguration(JPAConfigurationTaskWithEnvers.java:36)
            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)
            at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
            at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            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)


            Is there a way to define my classes differently that Envers will not complain. (This doesn't seem to be the case described when you need an AuditJoinTable annotation since there is already a join table)

            Thanks,
            Brocha

            • 3. Re: Problem generating schema from ant
              adamw

              Hello,

              is a combination @JoinTable and @ManyToOne valid at all? Normally in such cases the id of the related entity is stored in the entity on the many-side (here: personId in Address), so you just really need @ManyToOne. Does this work with Hibernate?

              I haven't tested such a mapping, so I would have to see what happens here exactly :)

              Adam

              • 4. Re: Problem generating schema from ant

                Hi,

                Yes, this works with plain Hibernate (no Enverse). There is a table of addresses, a table of people, and a join-table of people-to-address that just has the IDs. From an Address object you can access the person and from the person object you can get the Set of Addresses.

                If this is not standard, how would you define the columns?

                Thanks,
                Brocha

                • 5. Re: Problem generating schema from ant
                  adamw

                  Hello,

                  well the "standard" way is to just have two tables (Person and Address) with a personId in the Address table.

                  But if the mapping works without envers, it should also work with it - can you please create a jira bug?

                  Adam