8 Replies Latest reply on May 23, 2012 6:33 AM by adamw

    revinfo table not created and some aud tables not created

    vyacheslav86

      I'm using enver, hibernate and spring.

       

      hibernate-config.properties file:

       

      hibernate.connection.pool_size=50

      hibernate.show_sql=true

      hibernate.dialect=ru.csbi.registry.utils.TableNameSequenceOracle10gDialect

      hibernate.cache.use_second_level_cache=true

      hibernate.cache.use_query_cache=true

      hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory

      hibernate.hbm2ddl.auto=update

      #hibernate.envers.default_schema=REALTY_NEW

      #Envers

      hibernate.ejb.event.post-insert=org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener

      hibernate.ejb.event.post-update=org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener

      hibernate.ejb.event.post-delete=org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener

      hibernate.ejb.event.pre-collection-update=org.hibernate.envers.event.AuditEventListener

      hibernate.ejb.event.pre-collection-remove=org.hibernate.envers.event.AuditEventListener

      hibernate.ejb.event.post-collection-recreate=org.hibernate.envers.event.AuditEventListener

       

      spring application context configuration:

       

      <bean id="sessionFactory"

              class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

              <property name="entityInterceptor">

                  <bean class="ru.csbi.registry.utils.audit.AuditLogInterceptor">

                      <property name="sessionFactory" ref="auditSessionFactory" />

                  </bean>

              </property>

              <property name="dataSource" ref="dataSource" />

              <property name="lobHandler" ref="oracleLobHandler" />

              <property name="packagesToScan" value="ru.csbi.registry.domain" />

              <property name="hibernateProperties">

                  <bean id="hibernatePropertiesFactoryBean"

                      class="org.springframework.beans.factory.config.PropertiesFactoryBean">

                      <property name="locations">

                          <list>

                              <value>file:${realtyregistry.settings.path}/hibernate-config.properties

                              </value>

                          </list>

                      </property>

                  </bean>

              </property>

              <property name="eventListeners">

                  <map>

                      <entry key="post-insert" value-ref="auditEventListener" />

                      <entry key="post-update" value-ref="auditEventListener" />

                      <entry key="post-delete" value-ref="auditEventListener" />

                      <entry key="pre-collection-update" value-ref="auditEventListener" />

                      <entry key="pre-collection-remove" value-ref="auditEventListener" />

                      <entry key="post-collection-recreate" value-ref="auditEventListener" />

                  </map>

              </property>

          </bean>

       

          <bean id="auditEventListener" class="org.hibernate.envers.event.AuditEventListener" />

       

      schema update gets executed because server startup time grows by a number of 10 after hibernate.hbm2ddl.auto=update switch is turned on.

       

      Aud tables created only for entities without @OneToMany @ManyToOne and @OneToOne realtions, for example : property entity has no aud table after startup.

       

      @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, include = "all")

      @JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })

      @Entity

      @Table(name = "PROPERTIES")

      @Inheritance(strategy=InheritanceType.SINGLE_TABLE)

      @DiscriminatorColumn(name="BASE_TYPE_ID", discriminatorType=DiscriminatorType.INTEGER)

      @Audited

      public class Property implements Auditable, Serializable {

          private static final long serialVersionUID = -7827695648259800469L;

       

          public Property() {}

       

          @Override

          public boolean equals(Object o) {

              if(this == o) return true;

              // new objects never equals!

              if(o == null || getId() == null || !(o instanceof Property)) return false;

              Property other = (Property) o;

              return getId().equals(other.getId());

          }

       

          @Override

          public int hashCode() {

              if(getId() == null) return 0;

              return getId().hashCode();

          }

       

          @Override

          public String toString() {

              return getName() + " (" + this.getNumber() + ")";

          }

       

          /**

           * Идентификатор записи в базе

           */

          @Id

          @GeneratedValue

          @Column(name = "ID")

          private Long id;

       

          public Long getId() {

              return this.id;

          }

       

          public void setId(Long id) {

              this.id = id;

          }

       

          /**

           * Базовый тип объекта

           */

          @OneToOne(/*fetch = FetchType.LAZY*/)

          @JoinColumn(name = "BASE_TYPE_ID", insertable=false, updatable=false)

          private PropertyBaseType baseType;

         

          public PropertyBaseType getBaseType() {

              return baseType;

          }

         

          public void setBaseType(PropertyBaseType type) {

              baseType = type;

          }

       

      but PropertyBaseType has aud table created in db:

       

      @Audited(auditParents={ReferenceBook.class})

      @Entity

      @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, include = "all")

      @Table(name = "REF_PROPERTY_BASE_TYPES")

      public class PropertyBaseType extends ReferenceBook {

          public static final String ATM = "atm";

          public static final String BUILDING = "building";

          public static final String ADV = "adv";

          public static final String FACILITY = "facility";

          public static final String LAND = "land";

      }

       

      @JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })

      @MappedSuperclass

      public abstract class ReferenceBook {

          @Id

          @NotNull

          @GeneratedValue

          @Column(name = "ID")

          protected Long id;

       

          @Column(name = "NAME")

          @Size(min = 1, max = 300)

          @NotNull

          @Sort

          protected String name;

       

          @Column(name = "CODE", unique = true)

          @Size(min = 1, max = 30)

          @NotNull

          protected String code;

       

          @Column(name = "POSITION")

          protected Long position;

       

          public Long getId() {

              return id;

          }

       

          public void setId(Long id) {

              this.id = id;

          }

       

          public String getName() {

              return name;

          }

       

          public void setName(String name) {

              this.name = name;

          }

       

          public String getCode() {

              return code;

          }

       

          public void setCode(String code) {

              this.code = code;

          }

       

          public Long getPosition() {

              return position;

          }

       

          public void setPosition(Long position) {

              this.position = position;

          }

       

          @Override

          public String toString() {

              if (name != null)

                  return name + " (" + code + ")";

              else

                  return code;

          }

         

          /**

           * Представление справочника для списка

           */

          public class ListRepr {

              public Long getId() {return ReferenceBook.this.getId();}

              public String getCode() {return ReferenceBook.this.getCode();}

              public String getName() {return ReferenceBook.this.getName();}

              public Long getPosition() {return ReferenceBook.this.getPosition();}

          }

         

      }

       

      And during change of one of PropertyBaseType properties REVINFO table gets inserted but throw an exception maybe because it is not created in db schema too by that moment:

       

      Could not execute JDBC batch update; SQL [insert into REVINFO (REVTSTMP, REV) values (?, ?)]

       

      If REVINFO is created by CREATE TABLE ddl script - modification operation is audited successfully.