Foreign key constraint should not be generated when <any> is used as element in a collection

Description

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.

Environment

hibernate verson = 3.3.0.sp1, db=h2

Activity

Show:
Rice Yeh
May 10, 2009, 5:43 AM

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.

Brett Meyer
December 5, 2013, 8:01 PM

If this is still an issue, anyone have a test case to attach?

Brett Meyer
December 19, 2013, 10:31 PM

Note: In an attempt to clean up the HHH JIRA, we will be rejecting any ticket that sits in the "Awaiting Test Case" state for 2-3 months with no response. So, if this issue is critical to you, please attach a reproducing test case ASAP. Thanks!

Brett Meyer
March 3, 2014, 3:41 PM

Bulk rejecting issues lacking a test case or recent response.

Rejected

Assignee

Unassigned

Reporter

Rice Yeh

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure