Usuf Arif:
uarif@tiaa-cref.org
I have posted this two days ago, but no replies yet, may be I did not explain it properly. Will try again.
We have a scenario where Child extends Parent and Child has many-to-one relationship with another table. When I try to insert a Child, hibernate complains that it can not insert null value in the foreign key of the Child table. I have written code exactly as the documentation preaches, and forum is the only place I can get the answer. Any help will be greatly appreciated.
Plan extends BasePlan.
Plan has many-to-one relationship with PlanLkup.
BasePlan.hbm.xml file has a <joined-subclass> attribute for Plan, inside this attribute, there is many-to-one relationship with PlanLkup.
================BasePlan.hbm.xml=================
<class
name="persistence.BasePlan"
table="BASE_PLAN"
>
<!--................Other attributes of BasePlan table here ........-->
<joined-subclass name="persistence.inst7307.Plan"
table="PLAN">
<key column="PLAN_ID"/>
<many-to-one
name="PlanLkup"
class="persistence.inst7307.lookup.PlanLkup"
not-null="true">
<column name="LOOK_UP_ID" />
</many-to-one>
</joined-subclass>
</class>
=====================================
================PlanLkup.hbm.xml=========
<hibernate-mapping>
<class
name="persistence.inst7307.lookup.PlanLkup"
table="PLAN_LKUP"
>
<id
name="lookUpId"
type="int"
column="LOOK_UP_ID"
>
<generator class="sequence" />
</id>
<!--........................Other properties.......................................-->
<!-- associations -->
<!-- bi-directional one-to-many association to Plan -->
<set
name="plans"
lazy="true"
inverse="true"
>
<key>
<column name="LOOK_UP_ID" />
</key>
<one-to-many
class="persistence.inst7307.Plan"
/>
</set>
</class>
</hibernate-mapping>
=====================================
Plan has a many-to-one relationship with PlanLkup with LOOK_UP_ID.
In the Java code, I have established bidirectional relationship between Plan and PlanKkup as follows:
/****************************************************
plan.setPlanLkup(planLkup); //chlild.set(Parent)
planLkup.getPlans().add(plan); //parent.getChildren.add(child)
****************************************************/
The above code is supposed to establish relationship between Plan and PlanLkup with LOOK_UP_ID. PlanLkup is not null. I was expecting that hibernate will pickup the LOOK_UP_ID from the PlanLkup and insert it into the Plan.
//////////////////////Error I get://///////////////////////////////////////////
150062 [main] ERROR net.sf.hibernate.util.JDBCExceptionReporter - ORA-01400: cannot insert NULL into ("CCS01"."PLAN"."LOOK_UP_ID")
///////////////////////////////////////////////////////////////////
Any recommendations are highly appreciated!
Email:
uarif@tiaa-cref.org