-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: foreign key contraint used for 'any' association
PostPosted: Thu Jan 19, 2006 1:57 pm 
Newbie

Joined: Thu Jan 19, 2006 1:44 pm
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.