4 Replies Latest reply on Feb 10, 2009 6:10 AM by gonzaloferreyra

    Problem with @VersionsJoinTable

    gonzaloferreyra

      Hello I'm facing a trouble when trying to audit an entity with a bidirectional collection;

      We are using Glassfish v2 as App Server, EJB 3 for business rules layer and Hibernate for the data layer, with PostgreSQL 8.3.

      The Envers version it's 1.1.0 GA for Hibernate 3.3.

      These are the entities: (the relevant parts of them... )

      @Entity
      @Table(name="comitente")
      @Versioned
      @VersionsTable(schema="auditoria", value="comitente_auditoria")
      public class Comitente implements Serializable {
      ...
       @OneToMany(mappedBy = "comitente",
       cascade={CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.REMOVE})
       @VersionsJoinTable(schema="auditoria",
       name="comitente_sede_comitente_auditoria")
       private List<SedeComitente> sedes = new ArrayList();
      
      ...
      }
      
      @Entity
      @Table(name="sede_comitente")
      @Versioned
      @VersionsTable(schema="auditoria", value="sede_comitente_auditoria")
      public class SedeComitente implements Serializable {
       @ManyToOne(fetch=FetchType.EAGER)
       @JoinColumn(name="comitente_id", nullable=false)
       private Comitente comitente;
      ...
      }
      
      


      Every time we try to persist a new instance of Comitente, we are falling in this situation...

      javax.ejb.EJBException: Transaction aborted; nested exception is: javax.transaction.RollbackException: Transaction marked for rollback.
      javax.transaction.RollbackException: Transaction marked for rollback.....
      


      It's something we are missing? When the app it's deployed, the VersionsJoinTable "auditoria.comitente_sede_comitente_auditoria" it's never created.....

      In postgres log whe coudn't get any error, so we think the problem it's in creating the vertsion of the relationship

      Thanks in advance

      Gonzalo

        • 1. Re: Problem with @VersionsJoinTable
          adamw

          Hello,

          your mapping is wrong. @VersionsJoinTable only has sense when you have a unidirectional one-to-many or many-to-many mapping. In your case, the mapping is bidirectional, and no additional join table is necessary.

          Also, the exception isn't too informative, it's missing the most important part - where it actually happened :)

          --
          Adam

          • 2. Re: Problem with @VersionsJoinTable
            gonzaloferreyra

            Thanks a lot Adam, i really misunderstood it. The problem was solved deleting that annotation, but I yet got a doubt:
            If I insert two registers into the database via sql, one instance of Comitente, and the other instance of SedeComitente, for example, and then I try to add the instance of SedeComitente to the collection programatically, I should fill via sql the audit tables too?

            That issue it's stopping me to continue the developing of the test cases for the EJB module, that's why I'm asking it again :(.

            Thanks again.

            Gonzalo

            • 3. Re: Problem with @VersionsJoinTable
              adamw

              Hello,

              if you add some data not with Hibernate, then if you want the history-reading to work properly, you should also add the data to the audit tables.

              --
              Adam

              • 4. Re: Problem with @VersionsJoinTable
                gonzaloferreyra

                Thanks again Adam, I'll do it this way.

                Thanks a lot

                Gonzalo