This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes  many to one twice referring to the same parent table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark " many to one twice referring to the same parent table" Watch " many to one twice referring to the same parent table" New topic
Author

many to one twice referring to the same parent table

suru Hajare
Greenhorn

Joined: Apr 10, 2012
Posts: 1
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
 
wood burning stoves
 
subject: many to one twice referring to the same parent table
 
Similar Threads
Problem with joining of two tables with Hibernate
org.hibernate.HibernateException: identifier of an instance of Address was altered from 2 to 3
concurrent insertion
Hibernate: Different Join in Save() and Get()
Hibernate problem - creating duplicate foreign key index