3 Replies Latest reply on Jan 30, 2013 3:57 PM by adamw

    Single Revision for Multiple Schemas

    sebp

      I have a database with multiple schemas and I want to have a single, global revision. Therefore I defined the revision entity as follows:

       

      @Entity(name = "Revision")
      @Table(name = "revision", schema = "space")
      @SequenceGenerator(name = "RevisionSequence", sequenceName = "space.seq_revision", initialValue = 1, allocationSize = 1)
      @RevisionEntity(UserRevisionListener.class)
      public class AuditRevisionEntity implements Serializable, BasicRevisionEntity {
          private static final long serialVersionUID = 1L;
      
          private Long id;
          private long timestamp;
          private String userName;
      
          @Override
          @RevisionNumber
          @Id
          @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "RevisionSequence")
          @Column(name = "id")
          public Long getId() {
              return this.id;
          }
      
      ...
      
      }
      

       

      This revisionn entity is used by all persistence units, e.g.:

       

       

      <persistence version="1.0"
          xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
          <persistence-unit name="PatientManagementChimerism">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>java:PatientManagementDS</jta-data-source>
              <class>com.qualitype.audit.entity.AuditRevisionEntity</class>
              ....
           </persistence-unit>
      </persistence>
      

       

      It works fine. I have a global revision entity and I can do nice horizontal audits from one schema to another. But I'm not sure if this is the right way to do it, since I didn't find any envers tutorial that explains how to use global revisions on multiple schemas. Also, as you can see, the revision name contains the schema of the revision table (sequenceName = "space.seq_revision"). Hibernate seems to accept that even if this is not part of the JPA spec. My question is: Is this the right way to do it (are there alternatives)?

        • 1. Re: Single Revision for Multiple Schemas
          hernanbolido

          Hi Sebastian,

           

          I remember talking about this in old posts... I don´t know if it's the same issue, but it's the same idea.

           

          Here are some links with this:

           

          http://community.jboss.org/message/529358#529358

          http://community.jboss.org/message/602484#602484

           

          I hope it will be helpful.

           

          Regards. Hernán.

          1 of 1 people found this helpful
          • 2. Re: Single Revision for Multiple Schemas
            sacortes

            Hi, i have the same scene of Sebastian Lorenz.

             

            I have two schemas with different entities, and they are related.


            @Audited
            SchemaA.entityA have an attribute of

            @Audited

            SchemaB.entityB.

             

            By default, we have two REVINFO tables, one per schema, but this give us problems, because of the Rev Numbers...

             

            If we try to load SchemaA.entityA, envers use the revision number of SchemaA.REVINFO Table, to find the SchemaB.entityB, that is using another REVINFO (the SchemaB one).

             

            Using the solution explained by Sebastian will solve our issue... Is that a correct solution? Is a correct configuration for @RevisionEntity?

             

            I readed the new posts links but they are related to Replication databases and migrations, i'm working in a Database from 0.

             

            Thanks in advance,

            Sebastian

            • 3. Re: Single Revision for Multiple Schemas
              adamw

              Sebastian's solution looks good. If you need globally unique revisions, just ensure that the revision numbers will be unique.

               

              Adam