1 Reply Latest reply on Mar 14, 2012 5:18 PM by adamw

    Auditing a map of child entities as values

    yairs

      Hi,

       

      I have a Parent entity that refers a Child entity as a value in a map (see below). The key in the map is an enum. Unfortunately using @AuditJoinTable with table name doesn't create the expected "parent_children_aud" table. Is auditing for map references supported? Or is there something that I'm doing wrong?

       

      Thanks,

      Yair

       

      Parent class:

       

      @Audited
      public class Parent {
      
          private Long id;
          private Integer version;
      
          private Map<MyEnum, Child> mappedChildren;
      
          protected Parent() {}
          
          public Long getId() {
                return this.id;
           }
      
          public void setId(Long id) {
               this.id = id;
          }
      
          public Integer getVersion() {
              return version;
          }
      
          public void setVersion(Integer version) {
              this.version = version;
          }
      
          @AuditJoinTable(name = "parent_children_aud")
          public Map<MyEnum, Child> getMappedChildren() {
              return this.mappedChildren;
          }
      
          public void setMappedChildren(Map<MyEnum, TemplateStage> mappedChildren) {
              this.mappedChildren = mappedChildren;
          }
      }
      

       

      Child class:

      @Audited
      public class Child {
      
          private Long id;
      
          protected Child() {}
          
          public Long getId() {
                return this.id;
           }
      
          public void setId(Long id) {
               this.id = id;
          }
      
          public Integer getVersion() {
              return version;
          }
      
          public void setVersion(Integer version) {
              this.version = version;
          }
      }
      

       

      MyEnum:

      public enum MyEnum { AAA, BBB, CCC; }
      

       

      hbm.xml:

      <?xml version='1.0' encoding='utf-8'?>
      <!DOCTYPE hibernate-mapping PUBLIC
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
      
      <hibernate-mapping>
      
          <class name="Parent" table="parents">
              <cache usage="read-write"/>
              <id name="id" column="id">
                  <generator class="native"/>
              </id>
              <version name="version" unsaved-value="negative"/>
      
              <map name="mappedChildren" cascade="all-delete-orphan" lazy="true">
                  <cache usage="read-write"/>
                  <key column="parent_id"/>
                  <map-key type="MyEnum"/>
                  <one-to-many class="Child"/>
              </map>
      
          </class>
      
          <class name="Child" table="children">
              <cache usage="read-write"/>
              <id name="id">
                  <generator class="native"/>
              </id>
              <version name="version" unsaved-value="negative"/>
          </class>
      
      </hibernate-mapping>