@AuditMappedBy Help
code6226 Aug 11, 2010 8:03 AMMy project uses Hibernate Mappings (Hibernate 3.5.4). The two relevant abtract classes are AttributeValues and AttributesTypes. These are then joined-subclassed with the classes: TextAV / TextAT, NumberAV / NumberAT, EnumAV / EnumAT ... (respectively).
My issue is only with the last (EnumAV), for it seems to fall into the special case that needs the @AuditMappedBy annotation, as described here: http://docs.jboss.org/envers/docs/index.html#exceptions-onetomanyjoincolumn
AttributeValue HBM:
<class name="AttributeValue" table="AV" lazy="false"> <id name="id" column="ID" type="java.lang.Integer"> <generator> <param name="segment_value">av</param> </generator> </id> ... <joined-subclass name="TextAV" table="AV_TEXT" lazy="false"> <key column="ID_AV" /> <property name="value" column="VALUE" length="4000" /> <many-to-one name="attributeType" column="ID_AT" not-null="true" /> </joined-subclass> <joined-subclass name="EnumAV" table="AV_ENUM" lazy="false"> <key column="ID_AV" /> <property name="name" column="NAME" length="255" not-null="true" /> <property name="description" column="DESCRIPTION" length="4000" /> <many-to-one name="attributeType" column="ID_AT" not-null="true" insert="false" update="false" /> </joined-subclass>
AttributeType HBM:
<class name="AttributeType" table="AT" lazy="false"> <id name="id" column="ID" type="java.lang.Integer"> <generator> <param name="segment_value">av</param> </generator> </id> <property name="name" column="NAME" length="255" not-null="true" unique="true" /> <property name="description" column="DESCRIPTION" length="4000" /> <property name="mandatory" column="MANDATORY" length="1" not-null="true" /> <property name="position" column="POS" insert="false" update="false" /> ... <joined-subclass name="TextAT" table="AT_TEXT" lazy="false"> <key column="ID_AT" /> <property name="multiline" column="MULTILINE" length="1" not-null="true" /> <set name="attributeValues" lazy="true" inverse="true" cascade="all"> <key column="ID_AT" /> <one-to-many /> </set> </joined-subclass> <joined-subclass name="EnumAT" table="AT_ENUM" lazy="false"> <key column="ID_AT" /> <property name="multiassignmenttype" column="MULTIVALUE" length="1" not-null="true" /> <list name="attributeValues" lazy="true" cascade="all"> <key column="ID_AT" not-null="true" /> <list-index column="POS" /> <one-to-many /> </list> </joined-subclass>
The issue is that when I use Envers to retrieve an old EnumAV, I can only get its Name, not its EnumAT .
Looking at the database tables (MySQL), the av_enum_aud table has all its ID_AT values null. The at_aud table also has the POS column with only null values.
Another table was created, however, called enumat_enumav_aud, which has all its columns filled in: ID_AT, ID_AV, POS, REVTYPE. Envers must not be reading from this additional table.
So I tried using @AuditMappedBy in various ways, but nothing seemed to change. Best example of how to use it that I could find was the ParentIndexedListJoinColumnBidirectionalRefIngEntity.java test case. Trying to use the same format myself, I came up with this:
Class:EnumAV (No change)
@Entity @Audited public class EnumAV extends AttributeValue { private String name; private String description; private EnumAT attributeType; ...
Class:EnumAT
@Entity @Audited public class EnumAT extends AttributeType implements MultiassignementType { private boolean multiassignmenttype; @AuditMappedBy(mappedBy = "attributeType", positionMappedBy = "position") private List<EnumAV> attributeValues = new ArrayList<EnumAV>();
The "position" Integer is defined in the AttributeType abstract class.
This didn't seem to have any effect... What should I do?