I have been tasked with evaluating Hibernate against a legacy DB schema and it has proved rather difficult. My current problem seems to stem from what appear to be rather complex associations using composite IDs.
for example:
Code:
<hibernate-mapping>
...
<class name="myapp.hibernate.Tia00571" table="TIA00571" schema="MYAPP" >
<composite-id name="comp_id" class="myapp.hibernate.Tia00571PK">
<!-- bi-directional many-to-one association to Tia00570 -->
<key-many-to-one name="tia00570" class="myapp.hibernate.Tia00570">
<column name="CLAIM_CASE_NUMBER" />
</key-many-to-one>
<!-- bi-directional many-to-one association to Tia00569 -->
<key-many-to-one name="tia00569" class="myapp.hibernate.Tia00569">
<column name="CNTR_ID" />
</key-many-to-one>
</composite-id>
<property name="titleType" type="java.lang.String" column="TITLE_TYPE" length="1" />
...etc...
<property name="maintUserId" type="java.lang.String" column="MAINT_USER_ID" not-null="true" length="7" />
<!-- associations -->
<!-- bi-directional one-to-many association to Tia00596 -->
<set name="tia00596s" lazy="true" inverse="true" >
<key>
<column name="CLAIM_CASE_NUMBER" />
<column name="CNTR_ID" />
</key>
<one-to-many class="myapp.hibernate.Tia00596" />
</set>
<!-- bi-directional one-to-many association to Tia00582 -->
<set name="tia00582s" lazy="true" inverse="true" >
<key>
<column name="CLAIM_CASE_NUMBER" />
<column name="CNTR_ID" />
</key>
<one-to-many class="myapp.hibernate.Tia00582" />
</set>
<!-- bi-directional one-to-one association to Tia00573 -->
<one-to-one name="tia00573" class="myapp.hibernate.Tia00573" outer-join="auto" />
<!-- bi-directional one-to-many association to Tia00572 -->
<set name="tia00572s" lazy="true" inverse="true" >
<key>
<column name="CLAIM_CASE_NUMBER" />
<column name="CNTR_ID" />
</key>
<one-to-many class="myapp.hibernate.Tia00572" />
</set>
<!-- bi-directional one-to-many association to Tia00579 -->
<set name="tia00579s" lazy="true" inverse="true" >
<key>
<column name="CLAIM_CASE_NUMBER" />
<column name="CNTR_ID" />
</key>
<one-to-many class="myapp.hibernate.Tia00579" />
</set>
<!-- bi-directional one-to-many association to Tia00595 -->
<set name="tia00595s" lazy="true" inverse="true" >
<key>
<column name="CLAIM_CASE_NUMBER" />
<column name="CNTR_ID" />
</key>
<one-to-many class="myapp.hibernate.Tia00595" />
</set>
<!-- bi-directional one-to-many association to Tia00592 -->
<set name="tia00592s" lazy="true" inverse="true" >
<key>
<column name="CLAIM_CASE_NUMBER" />
<column name="CNTR_ID" />
</key>
<one-to-many class="myapp.hibernate.Tia00592" />
</set>
<!-- bi-directional one-to-one association to Tia00574 -->
<one-to-one name="tia00574" class="myapp.hibernate.Tia00574" outer-join="auto" />
</class>
</hibernate-mapping>
<hibernate-mapping>
...
<class name="myapp.hibernate.Tia00573" table="TIA00573" schema="MYAPP" >
<composite-id name="comp_id" class="myapp.hibernate.Tia00573PK">
<!-- bi-directional one-to-one association to Tia00571 -->
<key-many-to-one name="tia00571" class="myapp.hibernate.Tia00571" >
<column name="CLAIM_CASE_NUMBER" />
<column name="CNTR_ID" />
</key-many-to-one>
</composite-id>
<property name="leadContractId" type="java.lang.String" column="LEAD_CONTRACT_ID" not-null="true" length="10" />
...etc
<property name="maintUserId" type="java.lang.String" column="MAINT_USER_ID" not-null="true" length="7" />
<!-- associations -->
<!-- bi-directional one-to-one association to Tia00571 -->
<one-to-one name="tia00571" class="myapp.hibernate.Tia00571" outer-join="auto" constrained="true" />
<!-- bi-directional one-to-many association to Tia00575 -->
<set name="tia00575s" lazy="true" inverse="true" >
<key>
<column name="CLAIM_CASE_NUMBER" />
<column name="CNTR_ID" />
</key>
<one-to-many
class="myapp.hibernate.Tia00575"
/>
</set>
</class>
</hibernate-mapping>
When I try and run the simple query...
Code:
from myapp.hibernate.Tia00571
The association to the above table mapping causes it to try and load data from Tia00573...
Code:
select tia005730_.CLAIM_CASE_NUMBER as CLAIM_CA1_0_, tia005730_.CNTR_ID as CNTR_ID0_, tia005730_.LEAD_CONTRACT_ID as LEAD_CON3_0_, tia005730_.PROD_ID as PROD_ID0_, tia005730_.PRODUCT_VER_TYPE as PRODUCT_5_0_, tia005730_.TTL_EXC_CLOSED_IND as TTL_EXC_6_0_, tia005730_.TTL_EXC_CLOSED_DAT as TTL_EXC_7_0_, tia005730_.ISA_IND as ISA_IND0_, tia005730_.TARGET_MAT_VAL as TARGET_M9_0_, tia005730_.MAINT_USER_ID as MAINT_U10_0_ from CLEX.TIA00573 tia005730_ where tia005730_.CLAIM_CASE_NUMBER=? and tia005730_.CNTR_ID=?
...which when setting the values for the ? parameters, eventually calls the following method in
net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter...
Code:
public Object get(Object target) throws HibernateException {
try {
return method.invoke(target, null);
}
catch (InvocationTargetException ite) {...}
catch (IllegalAccessException iae) {...}
catch (IllegalArgumentException iae) {...}
}
The value of 'target' at this point is:
myapp.hibernate.Tia00571PK@15ea7901[
tia00570=myapp.hibernate.Tia00570@6c80f901[claimCaseNumber=1022],
tia00569=myapp.hibernate.Tia00569@5771b900[cntrId=UK52308103]
]
and the result is an "IllegalArgumentException in class: myapp.hibernate.Tia00573PK"
The code for Tia00573PK was generated using Middlegen-Hibernate-RC4 and is as follows...
Code:
The package myapp.hibernate;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */
public class Tia00573PK implements Serializable {
/** identifier field */
private myapp.hibernate.Tia00571 tia00571;
/** full constructor */
public Tia00573PK(myapp.hibernate.Tia00571 tia00571) {
this.tia00571 = tia00571;
}
/** default constructor */
public Tia00573PK() {
}
public myapp.hibernate.Tia00571 getTia00571() {
return this.tia00571;
}
public void setTia00571(myapp.hibernate.Tia00571 tia00571) {
this.tia00571 = tia00571;
}
public String toString() {
return new ToStringBuilder(this).append("tia00571", getTia00571()).toString();
}
public boolean equals(Object other) {
if ( !(other instanceof Tia00573PK) ) return false;
Tia00573PK castOther = (Tia00573PK) other;
return new EqualsBuilder().append(this.getTia00571(), castOther.getTia00571()).isEquals();
}
public int hashCode() {
return new HashCodeBuilder().append(getTia00571()).toHashCode();
}
}
Basically, is there an obvious fault in the above PK class or mapping. e.g composite id containing many-to-one links, that might lead to the IllegalArgumentException.
Many thanks in advance.
Chris