tags:

views:

70

answers:

0

hi, i am trying to do a 1-many polymorphic association and running into problems. I have a table ATable, which needs to map to foo.A class. foo.A has a one-to-many association with foo.I except foo.I is an interface. ie,

public class A{

private Set< I > references; 
..

}

I has two implementations I_1 and I_2 both of which map to two tables I_1Table and I_2Table.The inheritance hierarchy between I , I_1 and I_2 is mapped via table-per concrete class using unions. The hibernate mapping looks like:

< class name ="A" table="ATable" >

< id name="id" column="id"/ >

< set name="references" cascade="all" >

< key column="marginID"/ >

< one-to-many class name="I" / >

< /class>

< class name="I" abstract="true" >

< id name="marginID" column="marginID" >

< generator class="..."/ >

< /id >

< union-subclass name="I_1" table="I_1Table"/ >
< union-subclass name="I_2" table="I_2Table" >

< property name="extraProperty" column="extraProperty"/ >

< /union-subclass >

< /class >

with this mapping, i am able to do polymorphic queries and load data...but when i try to persist data through the set, it fails saying I not found. specify owner.objectname or use sp_help (I am using Sybase SQL) The issue seems to be that if i try to create an instance of I_1 and commit it, then everything works fine. but when i add the instance to an instance of A and cascade the flush, then hibernate seems to issue an additional SQL statement instead of

insert into I_1Table ...

i have: insert into I_1Table ... update I where marginID=?

now, I am not sure why hibernate issued a update statement here when I was declared to be abstract.

Also, how do i fix the mapping to make sure i can persist properly when dealing with one-to-many association with polymorphism (where the base type is an interface/ or abstract class)