Hi,
Just the document stated, it is impossible to specify a foreign key constraint for 'any' association. But I find the ddl generated by schema export tool still generates foreign key constraint. My hbm and generated ddl are as follows:
<class name="as.party.Organization" table="ORGANIZNATION">
<id name="oid" type="java.lang.Long">
<generator class="native"/>
</id>
<!-- 'class' is the default discriminator column-->
<discriminator/>
<!-- fields from as.relation.RelatorObject -->
<set name="toRelations" cascade="save-update,delete" inverse="true"> <key column="TO_OID"/> <one-to-many class="as.party.org.Accountability"/> </set> <set name="fromRelations" cascade="save-update,delete" inverse="true"> <key column="FROM_OID"/> <one-to-many class="as.party.org.Accountability"/> </set>
<!-- TODO need to map fields 'beforeChangedListeners' and 'afterChangedListeners'? -->
<!-- field from as.relation.Part -->
<property name="name" length="50" not-null="true"/>
<property name="type" type="partType"/>
<!-- TODO add mapping for field 'keys' -->
<!-- field from as.party.Party -->
<property name="locale" type="locale"/>
<property name="timeZone" type="timezone"/>
<!-- TODO add mapping for field 'addresses', 'plays' -->
<subclass name="xs.school.TeachingOrganization">
<subclass name="xs.school.School"/>
<subclass name="xs.school.Department"/>
<subclass name="xs.school.Class"/>
</subclass>
</class>
<class name="as.party.Person" table="PERSON">
<id name="oid" type="java.lang.Long">
<generator class="native"/>
</id>
<!-- 'class' is the default discriminator column-->
<discriminator/>
<!-- fields from as.relation.RelatorObject -->
<set name="toRelations" cascade="save-update,delete" inverse="true"> <key column="FROM_OID"/> <one-to-many class="as.party.org.Accountability"/> </set> <set name="fromRelations" cascade="save-update,delete" inverse="true"> <key column="TO_OID"/> <one-to-many class="as.party.org.Accountability"/> </set>
<!-- TODO need to map fields 'beforeChangedListeners' and 'afterChangedListeners'? -->
<!-- fields from as.relation.Part -->
<property name="name" length="50" not-null="true"/>
<property name="type" type="partType"/>
<!-- TODO add mapping for field 'keys' -->
<!-- fields from as.party.Party -->
<property name="locale" type="locale"/>
<property name="timeZone" type="timezone"/>
<!-- TODO add mapping for field 'addresses', 'plays' -->
<!-- fields from as.party.Person -->
<property name="birthday" type="time2tuz">
<column name="BIRTHDAY_TIME_TIME"/>
<column name="BIRTHDAY_TIME_UNIT" length="20"/>
<column name="BIRTHDAY_TIMEZONE" length="20"/>
</property>
<property name="gender" type="gender">
<column name="GENDER" length="1"/>
</property>
</class>
<class name="as.party.org.Accountability" table="ACCOUNTABILITY">
<id name="oid" type="java.lang.Long">
<generator class="native"/>
</id>
<discriminator>
</discriminator>
<property name="type" type="relationType"/>
<any name="from" meta-type="string" id-type="java.lang.Long"> <column name="FROM_CLASS"/> <column name="FROM_OID"/> </any> <any name="to" meta-type="string" id-type="java.lang.Long"> <column name="TO_CLASS"/> <column name="TO_OID"/> </any>
<property name="effective" type="period">
<column name="EFFECTIVE_PERIOD_START_TIME"/>
<column name="EFFECTIVE_PERIOD_START_UNIT" length="20"/>
<column name="EFFECTIVE_PERIOD_START_TIMEZONE" length="20"/>
<column name="EFFECTIVE_PERIOD_END_TIME"/>
<column name="EFFECTIVE_PERIOD_END_UNIT" length="20"/>
<column name="EFFECTIVE_PERIOD_END_TIMEZONE" length="20"/>
</property>
<subclass name="xs.school.SubjectOfStudy">
<many-to-one name="student"/>
</subclass>
</class>
the generated foregin key constraint ddl for ACCOUNTABILITY:
alter table ACCOUNTABILITY add constraint FKFE08B25DFD51336E foreign key (FROM_OID) references PERSON alter table ACCOUNTABILITY add constraint FKFE08B25D261BAA4C foreign key (FROM_OID) references ORGANIZNATION alter table ACCOUNTABILITY add constraint FKFE08B25D13B759BF foreign key (TO_OID) references PERSON alter table ACCOUNTABILITY add constraint FKFE08B25D3C81D09D foreign key (TO_OID) references ORGANIZNATION
Hibernate version:3.1.1
Name and version of the database you are using:hdqldb 1.8.0.2
Regards,
Rice
|