9 Replies Latest reply on Dec 9, 2010 9:34 AM by arnieoag

    Revision table 'REVINFO' not created

    servaispe

      Hi everybody,

       

      I am testing Envers's features and there is a case where the revision table is not created. I am wondering if this is a bug or not.

       

      I am using Hibernate 3.5.2 with the following working (partial) configuration :

       

      [META-INF/persistence.xml]

       

      <persistence version="2.0"

        <persistence-unit name="party" transaction-type="RESOURCE_LOCAL">

      ...

        <properties>

          <property name="hibernate.hbm2ddl.auto" value="update" />

          <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

          <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/MODEL?useUnicode=true&amp;characterEncoding=UTF-8" />

          <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
          <property name="javax.persistence.jdbc.user" value="root" />
          <property name="javax.persistence.jdbc.password" value="" />

          ...

          <property name="org.hibernate.envers.default_schema" value="AUDIT"/>

        ...

        <!-- All EventListeners Are Defined -->

      </persistence-unit>

       

      [META-INF/orm.xml]

       

      <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
        version="2.0">
        <access>FIELD</access>
        <entity class="com.company.model.Party">
          <table name="PARTY" schema="MODEL" />

          ...

         </entity>

      ...

      </entity-mappings>

       

      The PARTY table is created into the MODEL schema and the audit table PARTY_AUD is created into the AUDIT schema. But the REVINFO table is created into the MODEL schema... More over, if the connection URL is defined as follow, the REVINFO table is not even created :

       

      jdbc:mysql://localhost?useUnicode=true&amp;characterEncoding=UTF-8

       

      As you can see, no schema is specified in this URL; which is legal (at least with mysql ) Anyway, to be able to see the REVINFO table created into the AUDIT schema, I had to specify the URL as follow :

       

      jdbc:mysql://localhost/AUDIT?useUnicode=true&amp;characterEncoding=UTF-8

       

      And this is exactly why I had to specify the schema for the table element into the entity-mapping file...

       

      So here is my question : is it a bug or I just don't use the Envers module very well ?

       

      Please, note that I am a newbie using JPA/Hibernate/Envers trying to figure out how it works. Also : my next test with Envers and Hibernate is to define two persistence units; each one defined with a different schema and with at least one entity from the first unit referencing an entity from the other unit. Anyone know if this is a possible use case for these tools ?

        • 1. Re: Revision table 'REVINFO' not created
          adamw

          The revision info table is created int he default schema. If you want to place it somewhere else, try creating a custom revision entity, then you have full control (it's very simple, see the docs)

           

          Adam

          1 of 1 people found this helpful
          • 2. Re: Revision table 'REVINFO' not created
            servaispe

            Hi Adam,

             

            Thank you for your answer. I will try to create a custom revision entity but, honestly, this is not as flexible as setting a property like the "org.hibernate.envers.default_schema" one. Let's think about the Maven's resource filtering feature in order to dynamically filter the default_schema value on the fly :

             

            [persistence.xml]

            ...

            <property name="org.hibernate.envers.default_schema" value="${target.audit_schema}"/>

            ...

             

            [pom.xml]

            ...

            <properties>
               <target.audit_schema>DEFAULT_AUDIT_SCHEMA</target.audit_schema>
            </properties>

            <profiles>

                <profile>
                  <id>myId</id>
                  <properties>
                    <target.audit_schema>myAUDIT_SCHEMA</target.audit_schema>
                  </properties>
                </profile>

            </profile>

            ...

             

            Using annotation, I don't think it is possible to use different values for the target audit schema, is it ?

             

            Note : I think Envers is a very cool and usefull module : it fills a real need in the data management community.

             

            Pascal-Eric

            • 3. Re: Revision table 'REVINFO' not created
              adamw

              Ah now I understand, sorry I missed the default schema before

              If indeed the revinfo gets generated into the default schema, not into the audit default schema, then it's a bug.

              Please report in JIRA .

               

              As a workaround, as I said you can create a custom revision entity.

               

              Adam

              1 of 1 people found this helpful
              • 4. Re: Revision table 'REVINFO' not created
                servaispe

                Hi Adam,

                 

                Thank you for your answer. As requested, I created a report in JIRA.

                From now, I will continue my explorations.

                 

                Regards

                Pascal-Eric

                • 5. Re: Revision table 'REVINFO' not created
                  arnieoag

                  I am having an odd similar problem. My custom revision entity and listener classes are in a shared library (setup by someone else who is no longer working here) and that jar is included in our Seam applications in the root of the ear file.

                   

                  There is a lot of shared code that provides functionality to all Seam apps, including these two classes for Seam apps that what to use EnVers.

                   

                  The thing with the app I'm working on is:

                   

                  13:10:57,312 ERROR [JDBCExceptionReporter] Table 'olrap.revinfo' doesn't exist
                  13:10:57,312 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@ec6ea5
                  org.hibernate.exception.SQLGrammarException: could not insert: [org.hibernate.envers.DefaultRevisionEntity]

                  ...

                  Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'olrap.revinfo' doesn't exist
                      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                   

                  Which is right - revinfo does not exist, because its called audit_revision!

                   

                  Its like the envers library does not see my custom classes - but otherwise, the application runs. I even disabled all the auditing in the project and it worked as expected.

                   

                  I even added <entity class="us.tx.state.oag.seam.domain.audit.AuditRevision"/> to my app's orm.xml file, but that didn't help either.

                   

                  Another question: there are two JAR files needed: jboss-envers-1.0.0.GA.jar and jboss-envers-1.2.2.GA-hibernate-3.3.jar - which I put in the /lib folder of the server.

                   

                  Is that valid? Do either have to be deployed w/i each project?

                  • 6. Re: Revision table 'REVINFO' not created
                    hernanbolido

                    Hi!

                     

                    I think that jboss-envers-1.0.0.GA.jar and jboss-envers-1.2.2.GA-hibernate-3.3.jar are the same library but different version. So, you should only have the newer one deployed.

                    About the table not found... I think 'olrap.revinfo' isn't defined by envers, it must be some old name used in your app. Maybe you have some obsolete jars on the classpath?

                     

                    I hope it will help. Regards. Hernán.

                    • 7. Re: Revision table 'REVINFO' not created
                      arnieoag

                      No, they are different libs. The latter @Audited annotation and the former has the @RevisionEntity and items. Its very frustrating.

                      • 8. Re: Revision table 'REVINFO' not created
                        adamw

                        These are different versions of Envers. For sure you need only one - the newer

                         

                        Adam

                        • 9. Re: Revision table 'REVINFO' not created
                          arnieoag

                          That was the problem. The common library (the one with the custom listener and the entity) was built using the JBoss version (deployed at the server) but the actual Seam project had the .org version deployed in the ear.

                           

                          Putting only the .org version at the server and rebuilding the common library components to use the .org version solved the problems.