2 Replies Latest reply on Nov 24, 2009 6:19 AM by obeah

    Generate schema based on dynamic configuration

      Hello,

      I plan to use Envers in our project. Our hibernate configuration is built dynamically from java code.

      configuration = new AnnotationConfiguration();
       configuration.addProperties(hibernateProperties);
       // add resource files
       for (String resource : allMappingResources) {
       configuration.addResource(resource);
       }
       for(Class item : allAnnotatedClasses){
       configuration.addAnnotatedClass(item);
       }


      Schema generation works then with this dynamically built configuration:

      SchemaUpdate schemaUpdate = new SchemaUpdate(configuration);
      schemaUpdate.execute(true, true);


      How can I integrate Envers tables generation into this code?

      Thank you



        • 1. Re: Generate schema based on dynamic configuration
          adamw

          Hello,

          I guess you should do something similar to what the EnversHibernateToolTask does. After you have created your configuration object, execute:

          AuditConfiguration.getFor(configuration);
          


          and then run the schema updates. That should do the trick.

          Adam

          • 2. Re: Generate schema based on dynamic configuration

            Hello,

            Thank you. It worked after I aslo added a call to configuration.buildMappings before getFor(). Final working code snippet below.


            configuration = new AnnotationConfiguration();
             configuration.addProperties(hibernateProperties);
             // add resource files
             for (String resource : allMappingResources) {
             configuration.addResource(resource);
             }
             for(Class<? extends Object> item : allAnnotatedClasses){
             configuration.addAnnotatedClass(item);
             }
             configuration.buildMappings();
             AuditConfiguration.getFor(configuration);
             SchemaUpdate schemaUpdate = new SchemaUpdate(configuration);
             schemaUpdate.execute(true, pExecuteScript);