I have an object which contains arrays of primitive types, so I am using the primitive-array to map these in hibernate.
example:
<primitive-array name="m_anAvgStateRank" table="AvgStateRank">
<key column="ID"/>
<index type="int"/>
<element type="int" column="AveStateRank" not-null="true" />
</primitive-array>
This object has a parent object and I cannot delete the primitive tables when I delete the parent object. I get a cannot update or delete parent due to foreign key constraint. I was trying to add the on-delete="cascade' attribute to the key tag, but I get a compaint from hibernate stating that it is not allowed with primitive-type. The dtd does not reflect this issue.
Here are my mapping files... any help would be greatly appreciated.
Core.hbm.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.SecureCognition.NTV.DataTypes.Core"
table="CORE">
<id name="id" column="CORE_ID" type="long">
<generator class="native"/>
</id>
<property name="name" column="name"/>
<property name="configFile" column="configFile"/>
<property name="bucketFile" column="bucketFile"/>
<property name="thermdefFile" column="thermdefFile"/>
<property name="startDate" column="startDate"/>
<property name="endDate" column="endDate"/>
<property name="verbose" column="verbose"/>
<property name="pid" column="pid"/>
<property name="mnKeepHours" column="mnKeepHours"/>
<property name="mnPauseSecs" column="mnPauseSecs"/>
<property name="mnSlideLength" column="mnSlideLength"/>
<property name="mnWindowLength" column="mnWindowLength"/>
<set name="coreResults" inverse="true" lazy="true" cascade="all,delete-orphan">
<key column="CORE_ID" on-delete="cascade"/>
<one-to-many class="com.SecureCognition.NTV.DataTypes.CoreResult"/>
</set>
</class>
</hibernate-mapping>
CoreResult.hbm.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping >
<class name="com.SecureCognition.NTV.DataTypes.CoreResult"
table="CORERESULT">
<id name="id" column="CORERESULT_ID" type="long">
<generator class="native"/>
</id>
<many-to-one name="core" class="com.SecureCognition.NTV.DataTypes.Core" column="CORE_ID"/>
<property name="m_nTime" column="m_nTime" type="integer"/>
<property name="m_nSize" column="m_nSize" type="integer"/>
<property name="m_nBuckets" column="m_nBuckets" type="integer"/>
<property name="m_nStates" column="m_nStates" type="integer"/>
<property name="m_nTotalEvents" column="m_nTotalEvents" type="integer"/>
<property name="m_nHighState" column="m_nHighState" type="integer"/>
<property name="m_nLowState" column="m_nLowState" type="integer"/>
<property name="m_nConStateSize" column="m_nConStateSize" type="integer"/>
<property name="m_fEntropy" column="m_fEntropy" type="double"/>
<property name="m_fEnergy" column="m_fEnergy" type="double"/>
<property name="m_fTemperature" column="m_fTemperature" type="double"/>
<property name="m_fMProduct" column="m_fMProduct" type="double"/>
<property name="m_fMXProduct" column="m_fMXProduct" type="double"/>
<property name="m_fMXTemp" column="m_fMXTemp" type="double"/>
<property name="m_bClicked" column="m_bClicked" type="boolean"/>
<property name="m_nStatesDisplayed" column="m_nStateDisplayed" type="integer"/>
<property name="m_nLastOffset" column="m_nLastOffset" type="long"/>
<property name="m_nLastSearchOffset" column="m_nLastSearchOffset" type="integer"/>
<property name="m_nRunningSum" column="m_nRunningSum" type="integer"/>
<property name="m_nLastIndex" column="m_nLastIndex" type="integer"/>
<primitive-array name="m_anAvgStateRank" table="AvgStateRank">
<key column="ID"/>
<index type="int"/>
<element type="int" column="AveStateRank" not-null="true" />
</primitive-array>
<primitive-array name="m_anAvgStateIndex" table="AveStateIndex">
<key column="ID"/>
<index type="int"/>
<element type="int" column="AveStateIndex" not-null="true"/>
</primitive-array>
<primitive-array name="m_afAvgStateT" table="AveStateT">
<key column="ID"/>
<index type="double"/>
<element type="double" column="AveStateT" not-null="true"/>
</primitive-array>
<primitive-array name="m_afAvgStateC" table="AveStateC">
<key column="ID"/>
<index type="double"/>
<element type="double" column="AveStateC" not-null="true"/>
</primitive-array>
<primitive-array name="m_afWorkArray" table="WorkArray">
<key column="ID"/>
<index type="double"/>
<element type="double" column="WorkArray" not-null="true"/>
</primitive-array>
<primitive-array name="m_afWork" table="Work">
<key column="ID"/>
<index type="double"/>
<element type="double" column="Work" not-null="true"/>
</primitive-array>
<primitive-array name="m_afStateCounts" table="StateCounts">
<key column="ID"/>
<index type="int"/>
<element type="int" column="StateCounts" not-null="true"/>
</primitive-array>
</class>
</hibernate-mapping>
This mapping does not work due to the foreign key constraint. If I comment out the primitive array mapping, I can delete a Core object and all the CoreResult Objects associated with the Core are deleted. I cannot do the same if I use the primitive-array types.
Rob
P.S. Using Hibernate-3.0 and Mysql 4.1.14
|