Hibernate version: 3 (not aware of the minor version if there is one)
Mapping documents: snippets below
Name and version of the database you are using: Oracle 10i
Okay, I'm throwing up my hands a bit earlier than I normally do on problems. I've been through mounds of docs and it's not really that I'm convinced that the answers aren't in there, but rather that I don't have the base level of know-how to really hone in on the solution. If you know of some documentation that explains this exact situation, then that's great too.
I have a new requirement to change how two objects relate in our system. There are two items, ManagementMethodType objects and each one of them has one HandlingType. This was accomplished by the MGMT_METHOD_TYPE table having a FK to the HANDLING_TYPE table. Now there is a lookup table, there can be up to four HandlingType objects for each ManagementMethodType object. The part that makes this hard is that there is a default HandlingType. In order to impact the rest of the system minimally I structured the ManagementMethodType object like so:
Code:
/**
* This is old and now will represent the new default HandlingType
*/
private HandlingType handlingType;
/**
* Here's the List of the new alternate HandlingType objects
*/
private List additionalHandlingTypes;
I see no reason why the HandlingType.hbm.xml mapping file needs to change in any way.
This is what I have for the ManagementMethodType.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jul 31, 2006 4:30:47 PM by Hibernate Tools 3.1.0.beta5 -->
<hibernate-mapping>
<class name="com.esmart.domain.type.ManagementMethodType" table="MGMT_METHOD_TYPE">
<cache usage="read-write"/>
<id name="id" type="long" unsaved-value="-1">
<column name="MGMT_METHOD_TYPE_ID" precision="10" scale="0" />
<generator class="native">
<param name="sequence">MGMT_METHOD_TYPE_ID_SEQ</param>
</generator>
</id>
<version name="revision" column="REVISION_ID" type="integer" />
<!-- This is how it was, somehow it needs to refer to the new mapping table, explained below -->
<many-to-one name="handlingType" class="com.esmart.domain.type.HandlingType">
<column name="HANDLING_TYPE_ID" precision="10" scale="0" />
</many-to-one>
<!-- This is how I believe one should do many-to-many from a lookup table -->
<set name="additionalHandlingTypes" table="MGMT_METHOD_HANDLING_CONTENT">
<key column="MGMT_METHOD_TYPE_ID"/>
<many-to-many column="HANDLING_TYPE_ID" class="com.esmart.domain.type.HandlingType"/>
</set>
<property name="code" type="string">
<column name="MGMT_METHOD_TYPE_CODE" length="4" not-null="true" unique="true" />
</property>
<property name="description" type="string">
<column name="MGMT_METHOD_TYPE_DESC" length="120" not-null="true" />
</property>
<property name="createdOn" type="timestamp">
<column name="CREATE_DATE" length="7" not-null="true" />
</property>
<property name="modifiedOn" type="timestamp">
<column name="UPDATE_DATE" length="7" />
</property>
<property name="modifiedBy" type="string">
<column name="MODIFIED_BY" length="8" />
</property>
<property name="expired" type="date">
<column name="END_DATE" length="7" />
</property>
</class>
</hibernate-mapping>
So here's a rough chart of the new table structure:
[img=http://img249.imageshack.us/img249/2479/hibernatequestionka4.th.gif](I should note that the contents of the DEFAULT_IND column is what makes something the default and the only two values are '0' and '1')
I want this to be able to persist back to the DB automatically or I think I could use some sort of filter with arbitrary SQL and update set to false. This O'Reilly article seems pretty close to what I'm trying to do, but they're using many-to-one while I need some sort of many-to-many structure
http://www.onjava.com/pub/a/onjava/2005/08/03/hibernate.html?page=3I imagine this little snippet is really at fault here:
Code:
<!-- This is how it was, somehow it needs to refer to the new mapping table, explained below -->
<many-to-one name="handlingType" class="com.esmart.domain.type.HandlingType">
<column name="HANDLING_TYPE_ID" precision="10" scale="0" />
</many-to-one>
<!-- This is how I believe one should do many-to-many from a lookup table -->
<set name="additionalHandlingTypes" table="MGMT_METHOD_HANDLING_CONTENT">
<key column="MGMT_METHOD_TYPE_ID"/>
<many-to-many column="HANDLING_TYPE_ID" class="com.esmart.domain.type.HandlingType"/>
</set>
... but I'm not sure what to try next. Any ideas?