-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: saved reference to object actually creates new one
PostPosted: Mon Jul 10, 2006 9:56 am 
Newbie

Joined: Tue Jun 13, 2006 9:03 am
Posts: 18
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 10:22 am 
Newbie

Joined: Wed Feb 01, 2006 10:33 am
Posts: 15
Have you tried: update="false" and insert="false"

Code:
<many-to-one
                name="b"
                class="Transaction"
                column="TRANSACTION_ID"
                cascade="all"
                 update="false"
                 insert="false"
                unique="true"/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 10:42 am 
Newbie

Joined: Tue Jun 13, 2006 9:03 am
Posts: 18
I just inserted those 2 attributes and reran the application but I still run into the same issue.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.