11 Replies Latest reply on May 21, 2008 4:04 AM by Adam Warski

    EnverHibernateToolTask generate invalide oracle table name (

    Louie Liu Newbie

      Hello,

      Thanks for your help to allow us using the ant task generate the DDL which including both the base tables and version tables from JPA objects.

      Since we are using the Oracle database, we run into some issue with the table name and oracle can not have table name starting _, when we run the sql to generate the database, it failed on creating the _revisions_info table.

      I wonder if you can help to fix it by remove _, or provide a option to allow not generating the _ for this table in ant task.

      Thanks a lot.

      Louie

        • 1. Re: EnverHibernateToolTask generate invalide oracle table na
          Adam Warski Master

          Hello,

          I don't have much time today (may holidays, time to leave the computer for a while :) ), but I think the best thing would be if you:
          * downloaded the development source package
          * edited the method org.jboss.envers.configuration.VersionsEntitiesConfiguration.getDefault()
          * build a package using "ant dist", the result will be in the dist category

          This of course will be configurable later :)

          Adam

          • 2. Re: EnverHibernateToolTask generate invalide oracle table na
            Anthony Whitford Newbie

            I was hoping that Envers could interrogate the DatabaseMetaData or Dialect to validate if a leading underscore is acceptable, but I can't find any such method.

            To Adam's point, I guess the best solution is to make the prefix for the additional revision columns configurable. The default could be "_", but then one could override it to be something like "ENVERS_" to make it work in Oracle. The key, though, is to make the prefix configurable at the persistence unit level or something because I don't want to have to repeat something like 'prefix="ENVERS_"' for every single @Versioned annotation.

            I look forward to the updated release.

            • 3. Re: EnverHibernateToolTask generate invalide oracle table na
              Anthony Whitford Newbie

              Thank you for adding the Generated Tables documentation.

              I would like to see the ability to override some default string literals using the persistence.xml, so something like:

              <persistence-unit name="myPersitenceUnit">
               <provider>org.hibernate.ejb.HibernatePersistence</provider>
               <jta-data-source>java:/myDatasource</jta-data-source>
               <properties>
               <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
               <property name="envers.version_table_suffix" value="_V"/>
               <property name="envers.version_column_prefix" value="V_"/>
               <property name="envers.revisions_info_table_name" value="V_REVISIONS_INFO"/>
               </properties>
              </persistence-unit>
              


              For example, the "_version" table suffix. In Oracle, there is a 30 character object name identifier limit. With that suffix, I can only use 22 characters for my Oracle table name. If I could change the suffix to be "_V", I would get up to 28 characters. I know I can use the @VersionsTable annotation, but I would prefer to avoid the extra annotation for every @Versioned class (the DRY principle).

              The "_revisions_info" table has the same problem as the version columns in that Oracle doesn't accept the preceding underscore.

              Oracle's limited object identifer name rules are frustrating, but it is a popular corporate standard.

              (Note that I think the persistence.xml file is a good logical place to define these settings, but I am open to alternatives. I simply want to stress that I want to be able to specify these things centrally in one place rather than adding extra annotations to each @Versioned class.)

              Thanks for your help. I look forward to the updates!



              • 4. Re: EnverHibernateToolTask generate invalide oracle table na
                Adam Warski Master

                Hello,

                that's exactly how I wanted to make these properties settable :). So if it's two of us, it must be right ;)

                One question, though: you can already set the name of the versions table, as well the names of it fields, using an (almost empty) entity annotated with @RevisionEntity (see http://www.jboss.org/envers/revision_log.html). Do you think the name of the versins table should be configurable both using properties and using @RervisionEntity?

                I'll hope I'll have time to implement it by next week.

                --
                Adam

                • 5. Re: EnverHibernateToolTask generate invalide oracle table na
                  Louie Liu Newbie

                  Thanks for your help always.

                  I think what we are asking is the revision related fields in the *_versions table which are generated from your code. If we have option to name those fields, we can overcome the oracle limitation.

                  Thanks a lot.

                  Louie

                  • 6. Re: EnverHibernateToolTask generate invalid oracle table nam
                    Anthony Whitford Newbie

                     

                    "adamw" wrote:
                    Hello,
                    One question, though: you can already set the name of the versions table, as well the names of it fields, using an (almost empty) entity annotated with @RevisionEntity (see http://www.jboss.org/envers/revision_log.html). Do you think the name of the versins table should be configurable both using properties and using @RervisionEntity?


                    One problem is that if we use the @RevisionsEntity mechanism, the "_revisions_info" table does not get skipped when running hbm2ddl -- that is a problem for us because the identifier violates Oracle's naming rules, so we can't execute the generated DDL... Basically, we would like to see the default _revisions_info table skipped IF a @RevisionsEntity exists. Alternatively, we simply need a way to override the "_revision_info" table name (hence the properties suggestion).

                    I know that you offer the feature whereby we can override the version table name using @VersionedTable. That is a great feature to have, but I would prefer to use that sparingly, not every time. Hence my suggestion to specify a property that overrides the default version table suffix.

                    Finally, we need a way to override the names for the the version columns (_version_id, _version, _version_type) -- or at least the prefix (as I suggested above) because Oracle doesn't like the preceding underscore.

                    In the mean time, we have had to modify your source code (as you suggested) to get this to work with Oracle. I am HOPING that with the next version that is released, we will have these configurable so that we don't need to create a custom version.

                    • 7. Re: EnverHibernateToolTask generate invalide oracle table na
                      Adam Warski Master

                      Hello,

                      I've uploaded a new version
                      (http://www.jboss.org/envers/downloads/development),
                      which has all the names mentioned above configurable.

                      For details, see
                      http://www.jboss.org/envers/configuration.html.

                      Adam

                      • 8. Re: EnverHibernateToolTask generate invalid oracle table nam
                        Adam Warski Master

                         

                        "awhitford" wrote:

                        One problem is that if we use the @RevisionsEntity mechanism, the "_revisions_info" table does not get skipped when running hbm2ddl


                        It should get skipped, and in my configuration it is skipped. Are you sure the entity annotated with @RevisionEntity is also annotated with @Entity? If yes, what's your configuration?

                        Adam

                        • 9. Re: EnverHibernateToolTask generate invalid oracle table nam
                          Anthony Whitford Newbie

                           

                          "adamw" wrote:
                          "awhitford" wrote:

                          One problem is that if we use the @RevisionsEntity mechanism, the "_revisions_info" table does not get skipped when running hbm2ddl


                          It should get skipped, and in my configuration it is skipped. Are you sure the entity annotated with @RevisionEntity is also annotated with @Entity? If yes, what's your configuration?

                          Adam


                          In my case, I think the issue is that the @RevisionEntity resides in a dependent jar because of refactoring.

                          • 10. Re: EnverHibernateToolTask generate invalide oracle table na
                            Anthony Whitford Newbie

                             

                            "adamw" wrote:
                            I've uploaded a new version
                            (http://www.jboss.org/envers/downloads/development),
                            which has all the names mentioned above configurable.

                            For details, see
                            http://www.jboss.org/envers/configuration.html.


                            Thanks Adam! This is very helpful!

                            • 11. Re: EnverHibernateToolTask generate invalide oracle table na
                              Adam Warski Master

                              Ah, I see. The generation of a default revisions info table is skipped if at the moment of generation, there is an entity on the classpath annotated with @RevisionEntity (and of course @Entity).

                              But maybe that not always need to be the case, so do you think an extra configuration option:
                              org.jboss.envers.generateDefaultRevisionInfo
                              would make sense?

                              Adam