2 Replies Latest reply on Mar 1, 2013 12:48 PM by adamw

    Envers - generate script for AUD tables

    damianb

      I work with database already created. The schema is not created or updated by Hibernate.

      Is there any way to generate script with DDL for AUD tables which then can be executed

      manually on the database?

       

      Thank you in advance for your help.

        • 1. Re: Envers - generate script for AUD tables
          damianb

          This method did the trick for me:

           

          enum Dialect {

              MYSQL("org.hibernate.dialect.MySQLInnoDBDialect"),

              ORACLE("org.hibernate.dialect.Oracle10gDialect"),

              SYBASE("org.hibernate.dialect.SybaseAnywhereDialect");

           

              private String className;

           

              private Dialect(String className) {

                  this.className = className;

              }

           

              public String getClassName() {

                  return className;

              }

          }

           

          private void createSchema(Dialect dialect, Class<?>... classes) {

               Configuration configuration = new Configuration();

               configuration.setProperty(Environment.DIALECT, dialect.getClassName());

                  for (Class<?> entityClass : classes) {

                      configuration.addAnnotatedClass(entityClass);

                  }

               configuration.buildMappings();

               AuditConfiguration.getFor(configuration);

           

               SchemaExport schemaExport = new SchemaExport(configuration);

               schemaExport.setDelimiter(";");

               schemaExport.setOutputFile(String.format("%s_%s.%s ", "ddl_audit", dialect.name().toLowerCase(), "sql"));

               boolean consolePrint = true;

               boolean exportInDatabase = false;

               schemaExport.create(consolePrint, exportInDatabase);

          }

          • 2. Re: Envers - generate script for AUD tables
            adamw

            That's also +/- what the generate-schema ant task does, see:

            http://docs.jboss.org/hibernate/core/4.1/devguide/en-US/html/ch15.html#envers-generateschema

            and the sources of the ant task.

             

            Adam