Hi,
I'm running into a little dilemma that may have to do with my understanding of hibernate. I have a class, call it A, that contains a reference to another class, call it B. During the initial run of the application, A and B get instantiated the reference in A is still null (A still does not know B). During a "refresh" of the application, the reference in A will get set to B via reflection. Below is a code snippet:
Code:
public class A {
private Transaction B;
//accessors to B
public void refresh() {
B = (Transaction)xxx.invoke(...);
System.out.println("B = " + B);
}
}
This works just fine during the run of the application (before a hibernate save and the load). When A and B are initialized, their references look like this:
A@1fbc355, Transaction@932fe. After the call to refresh, the system.out displays this for B: B = Transaction@932fe
Now I persist this to a database using hibernate and then retrieve it. When running the loaded data, the references look like this:
A@1fbc355, Transaction@932fe. After the call to refresh, the system.out displays this for B: B = Transaction@12a3r
Here the reference to Transaction in A is different than the actual object, i.e. they are not the same. Now I would assume that hibernate would create the Transaction object and set the reference to it in A, not create a new one. Here is my mapping for A:
Code:
<hibernate-mapping>
<class name="A" table="A">
....
<many-to-one
name="b"
class="Transaction"
column="TRANSACTION_ID"
cascade="all"
unique="true"/>
....
</hibernate-mapping>
<hibernate-mapping>
<class name="Transaction" table="Transaction">
....
</hibernate-mapping>
Is there a reason why hibernate creates a new reference? In the application, I need the reference to be the same in order to received changes from the Transaction object. thanks.
-nefi