2011-08-31 90 views
4

我正在使用envers來審計我的ParameterToValue實體。在envers生成的「values_for_params_AUD」數據庫表中,缺少在映射數據庫表「values_for_params」(常規Hibernate表)中顯示爲列的屬性「containerId」,「containerType」,「parameterId」。我需要能夠爲給定(containerId,containerType,parameterId)獲取歷史「值」。Envers審計表中缺少屬性

的ParameterToValue類:

@Audited 
public class ParameterToValue extends BasicValueHolder { 
private Long containerId; 
private ContainerType containerType; 
private Long parameterId; 

public ParameterToValue(ContainerID containerId, Long parameterId, Value value) { 
    super(value); 
    this.containerId = containerId.getContainerId(); 
    this.parameterId = parameterId; 
    containerType = containerId.getContainerType(); 
} 

ParameterToValue() { 
} 

public Long getParameterId() { 
    return parameterId; 
} 

public void setParameterId(Long parameterId) { 
    this.parameterId = parameterId; 
} 

public Value getValue() { 
    return value; 
} 

public void setValue(Value value) { 
    this.value = value; 
} 

public Long getContainerId() { 
    return containerId; 
} 

public void setContainerId(Long containerId) { 
    this.containerId = containerId; 
} 

public ContainerType getContainerType() { 
    return containerType; 
} 

public void setContainerType(ContainerType containerType) { 
    this.containerType = containerType; 
} 
} 

Hibernate映射定義:

<class name="platform.server.dataservices.model.ParameterToValue" table="values_for_params"> 
    <cache usage="read-write" include="all" /> 
    <id name="id" column="ID"> 
     <generator class="native"/> 
    </id> 
    <properties name="uniqueProps" unique="true"> 
     <property name="containerId" index="ParamValsContainerIdIndx"/> 
     <property name="parameterId" index="ParamValsParamIdIndx"/> 
     <property name="containerType" column="CONTAINER_TYPE"> 
      <type name="org.hibernate.type.EnumType"> 
       <param name="enumClass">platform.server.dataservices.model.ContainerType</param> 
       <param name="type">4</param> 
       <!-- 12 = string, 5 = smallint, 4 = integer, default 4 --> 
      </type> 
     </property> 
    </properties> 

    <many-to-one name="value" cascade="all" lazy="false" unique="true" index="PRM_VAL_IDX"/> 
</class> 

SHOW CREATE TABLE values_for_params在MySQL:

CREATE TABLE `values_for_params` (
    ID` bigint(20) NOT NULL AUTO_INCREMENT, 
    `containerId` bigint(20) DEFAULT NULL, 
    `parameterId` bigint(20) DEFAULT NULL, 
    `CONTAINER_TYPE` int(11) DEFAULT NULL, 
    `value` bigint(20) DEFAULT NULL, 
PRIMARY KEY (`ID`), 
UNIQUE KEY `value` (`value`), 
UNIQUE KEY `containerId` (`containerId`,`parameterId`,`CONTAINER_TYPE`), 
KEY `ParamValsParamIdIndx` (`parameterId`), 
KEY `ParamValsContainerIdIndx` (`containerId`), 
KEY `PRM_VAL_IDX` (`value`), 
KEY `FKE02CB4F981565307` (`value`), 
CONSTRAINT `FKE02CB4F981565307` FOREIGN KEY (`value`) REFERENCES `value` (`ID`) 
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 

SHOW CREATE TABLE values_for_params_AUD在MySQL:

CREATE TABLE `values_for_params_AUD` (
    `ID` bigint(20) NOT NULL, 
    `REV` int(11) NOT NULL, 
    `REVTYPE` tinyint(4) DEFAULT NULL, 
    `value` bigint(20) DEFAULT NULL, 
PRIMARY KEY (`ID`,`REV`), 
KEY `FKE093BE4AEB88DFB` (`REV`), 
CONSTRAINT `FKE093BE4AEB88DFB` FOREIGN KEY (`REV`) REFERENCES `DesignRevisionEntity`  (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 

回答

3

固定。如果有人需要的答案:

問題是envers忽略任何寫在屬性標記內。當我這樣去掉標籤:

<properties name="uniqueProps" unique="true"> 
    <property name="containerId" index="ParamValsContainerIdIndx"/> 
    <property name="parameterId" index="ParamValsParamIdIndx"/> 
    <property name="containerType" column="CONTAINER_TYPE"> 
     <type name="org.hibernate.type.EnumType"> 
      <param name="enumClass">platform.server.dataservices.model.ContainerType</param> 
      <param name="type">4</param> 
     </type> 
    </property> 
</properties> 

變成了:

<property name="containerId" index="ParamValsContainerIdIndx"/> 
<property name="parameterId" index="ParamValsParamIdIndx"/> 
<property name="containerType" column="CONTAINER_TYPE"> 
    <type name="org.hibernate.type.EnumType"> 
    <param name="enumClass">platform.server.dataservices.model.ContainerType</param> 
    <param name="type">4</param> 
    </type> 
</property> 

這樣一來,所有的屬性變得審計,但我仍然需要三重(數據筒,參數標識,containerType)是唯一。最終的解決方案是這樣的:

<property name="containerId" index="ParamValsContainerIdIndx"/> 
<property name="parameterId" index="ParamValsParamIdIndx"/> 
<property name="containerType" column="CONTAINER_TYPE"> 
    <type name="org.hibernate.type.EnumType"> 
    <param name="enumClass">platform.server.dataservices.model.ContainerType</param> 
    <param name="type">4</param> 
    </type> 
</property> 

<properties name="uniqueProps" unique="true"> 
    <property name="containerId" insert="false" update="false"/> 
    <property name="parameterId" insert="false" update="false"/> 
    <property name="containerType" insert="false" update="false"/> 
</properties> 
+1

謝謝!我有完全相同的問題。 – Bulat