Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

many to one twice referring to the same parent table

 
suru Hajare
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guyz,
Please let me know if you can help me for following problem:

Description:
We have defined hibernate mapping as follows,
"Base Table1" having unique key on column called as "code".
"Base Table2" have two foreign key based on "code" of "Base Table1".

we have defined many to one mapping in hbm file for "Base Table2" as follows:
<many-to-one name="alias1" entity-name="BaseEntity1" property-ref="UK_BaseEntity1" unique="false" fetch="join" update="true" insert="true" outer-join="true" optimistic-lock="true" not-found="exception" embed-xml="true">
<column name="Code1" not-null="true"/>
</many-to-one>
<many-to-one name="alias2" entity-name="BaseEntity1" property-ref="UK_BaseEntity1" unique="false" fetch="join" update="true" insert="true" outer-join="true" optimistic-lock="true" not-found="exception" embed-xml="true">
<column name="Code2" not-null="true"/>
</many-to-one>


Problem Faced:
1. Add record in "Base Table2" with Code1 = A1 & Code A2.
2. Fetch above record, then update above record with Code1= A3 & Code= A4.
In database, record is updated only with Code1=A4 & Code2=A4.


Observation:
We have observed that, when we fetch record from hibernate (session.get() method),
as Code1 & Code2 has same values, it gives same object reference for alias1 & alias2.
Hence, when we update values for alias1 and alias2, same value (i.e. A4) is updated in database.

Questions:
1. In above case, is there any configuration available in hibernate, by which even if foreign key values is same,
we will get different objects corresponding to that.
2. Any suggestion to handle the above case.


Thanks,
Suraj
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic