[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-3889) Foreign key constraint should not be generated when <any> is used as element in a collection
Rice Yeh (JIRA)
noreply at atlassian.com
Sat May 9 23:45:13 EDT 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3889?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=33132#action_33132 ]
Rice Yeh commented on HHH-3889:
-------------------------------
After deleting the above 2 foreign key constraints F1 and F2, I can successfully persist instances of C. However, I find another bug when accessing the set cs of C instances in either P1 or P2. The P_CLASS is not used as a condition in 'where' clause in the generated SQL, which obviously will cause problem when the P_OID for P1 and P2 are of the same value in C's table.
> Foreign key constraint should not be generated when <any> is used as element in a collection
> --------------------------------------------------------------------------------------------
>
> Key: HHH-3889
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3889
> Project: Hibernate Core
> Issue Type: Bug
> Components: core
> Affects Versions: 3.3.0.SP1
> Environment: hibernate verson = 3.3.0.sp1, db=h2
> Reporter: Rice Yeh
>
> Let P0, P1 and C are 3 classes. Both P0 and P1 have a set of C.
> This is like parent-child relationship. In C, there is a field p
> with type I, which is a interface shared by P0 and P1. These 3 classes are like below:
> class P0 implements I {
> Long oid;
> Set<C> cs;
> ...
> }
> class P1 implements I {
> Long oid;
> Set<C> cs;
> ...
> }
> class C {
> I p;
> ..
> }
> Their hbm mappings are like the following:
> <class name="P0">
> <id name="oid" type="java.lang.Long">
> <generator class="native"/>
> </id>
> <set name="cs" cascade="all,delete-orphan" inverse="true">
> <key column="P_OID" not-null="true"/>
> <one-to-many class="C"/>
> </set>
> </class>
> <class name="P1">
> <id name="oid" type="java.lang.Long">
> <generator class="native"/>
> </id>
> <set name="cs" cascade="all,delete-orphan" inverse="true">
> <key column="P_OID" not-null="true"/>
> <one-to-many class="C"/>
> </set>
> </class>
> <class name="C">
> <id name="oid" type="java.lang.Long">
> <generator class="native"/>
> </id>
> <any name="p" meta-type="string" id-type="long">
> <column name="P_CLASS"/>
> <column name="P_OID"/>
> </any>
> </class>
> Then 2 foreign key constraints F0 and F1 for P_OID in C to P0 and P1
> are created when generated DDL respectively. This is not right
> because persisting a object p0 in P0 will violate the constraint F1
> and persisting a object p1 in P1 will violate the constraint F0.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list