I'm using Hibernate 3.1 going against an Oracle 9 DB.
I have a class Order that contains a Set of AbstractFoos, and a String fooType. AbstractFoo has 3 subclasses (FooA, FooB, and FooC), which are each mapped to a different table. The Set will always be homogenous in that it will always contain instances of a single subclass. fooType indicates which type is stored in the Set.
The mapping file looks like:
Code:
<hibernate-mapping>
<class
name="c.e.e.t.view.order.bo.Order"
table="ORDER_MASTER"
lazy="false">
<property
name="fooType"
type="java.lang.String"
column="FOO_TYPE"
length="4"/>
<set
name="fooThings"
lazy="false"
inverse="true"
cascade="all-delete-orphan">
<key>
<column name="ORDER_NUMBER" />
<column name="REVISION_NUMBER" />
</key>
<one-to-many class="c.e.e.t.view.order.bo.nthing.AbstractPriorityNthing"/>
</set>
</class>
<class
name="c.e.e.t.view.order.bo.foo.AbstractFoo"
abstract="true"
lazy="false">
<composite-id
name="fooPriority"
class="c.e.e.t.view.order.bo.foo.Food">
....
</composite-id>
....
</class>
<union-subclass
name="c.e.e.t.view.order.bo.foo.FooA"
table="FOO_A"
extends="c.e.e.t.view.order.bo.foo.AbstractFoo"
lazy="false">
....
</union-subclass>
<union-subclass
name="c.e.e.t.view.order.bo.foo.FooB"
table="FOO_B"
extends="c.e.e.tview.order.bo.foo.AbstractFoo"
lazy="false">
....
</union-subclass>
<union-subclass
name="c.e.e.t.view.order.bo.foo.FooC"
table="FOO_C"
extends="c.e.e.t.view.order.bo.foo.AbstractFoo"
lazy="false">
....
</union-subclass>
</hibernate-mapping>
This is working fine unless I try to change the fooType. Let's say the Set contains FooCs. If I change the type to 'NONE' and clear the Set, the entries in FOO_C are deleted, and everything is great. However, if I change the type to FooB, clear the Set and populate it with FooB instances, when I execute merge() I get an exception that the Set contained the wrong type objects ('Object with id: null was not of the specified subclass: c.e.e.t.view.order.bo.foo.FooB (class of the given object did not match class of persistent copy)'). I want the entries in FOO_C to be deleted (as in the first case), and the new FooB instances to be persisted into FOO_B.
Is this possible? If so, what do I have to do? I've tried to clear the Set of the FooC instances and update the Set, but then I get 'instance has been deleted' on the merge.
Thanks,
Dave
I hope that this is readable. I couldn't figure out how to get it formatted properly. (Figured it out ;-} )