Hi Folks,
which kind of inheritance is the best way to map the
Accountability Analyis Pattern?
Here we have:
As you can see Person and Organiation are both Parties. This it correct to map the using
<many-to-any> and
many-to-one in (abstract) Party class.
Here what I did:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="de.grob.portal.domain.model.Accountablity"
table="ACCOUNTABILITIES"
proxy="de.grob.portal.domain.model.Accountablity"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="accountId"
column="ACCOUNT_ID"
type="long"
>
<generator class="native">
</generator>
</id>
<set
name="timePeriods"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="TIME_PERIOD_ID"
/>
<one-to-many
class="de.grob.portal.domain.model.TimePeriod"
/>
</set>
<set
name="types"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="ACCOUNT_TYPE_ID"
/>
<one-to-many
class="de.grob.portal.domain.model.AccountablityType"
/>
</set>
<set name="comissioners" lazy="true" inverse="false" cascade="none" sort="unsorted">
<key column="COMISSIONER_ID"/>
<many-to-any
id-type="string">
<!-- Person, Organization, Post -->
<column name="COMISSIONER_TYPE"/>
<column name="COMISSIONER_ID"/>
</many-to-any>
</set>
<set name="responsibles" lazy="true" inverse="false" cascade="none" sort="unsorted">
<key column="RESPONSIBILITY_ID"/>
<many-to-any
id-type="string">
<!-- Person, Organization, Post -->
<column name="RESPONSIBILITY_TYPE"/>
<column name="RESPONSIBILITY_ID"/>
</many-to-any>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="de.grob.portal.domain.model.Person"
table="PERSONS"
proxy="de.grob.portal.domain.model.Person"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="personId"
column="PERSON_ID"
type="long"
>
<generator class="native">
</generator>
</id>
<many-to-one
name="comissioner"
class="de.grob.portal.domain.model.Accountablity"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ACCOUNT_COMMISSIONER_FK"
/>
<one-to-one
name="responsbile"
class="de.grob.portal.domain.model.Accountablity"
cascade="none"
outer-join="auto"
constrained="true"
/>
</class>
</hibernate-mapping>
Or is it petter to use a different kind of mapping. As you can see Parties should be interchanable in Accountablity class.
Is there a common rule when to choose one of the thre inheritance mapping strategies?
Thx a lot!!!!
Bye
Toby