-->
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.  [ 2 posts ] 
Author Message
 Post subject: when are reverse relations be initilized?
PostPosted: Mon May 10, 2004 7:47 am 
Newbie

Joined: Thu Apr 08, 2004 7:17 am
Posts: 10
Hi,

I have a question about initialization of reverse relations in one-to-many relations.

Example:
public class A {
Collection b;
public Collection getB() {
return b;
}
}

public class B {
A a;
public A getA() {
return a;
}
}

Now I add an instance of class B to an instance of class A:
A a=session.load((new A).getClass(),pkForA);
B b=session.load((new B).getClass(),pkForB);
a.getB().add(b);

Now I tried to get A from B:
b.getA();

It returns null!

I have to close the session (session.flush() is not enough), start a new one and load B again.
Then b.getA() returns the right object.

Can I force hibernate to set the reverse relation without using a new session?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 8:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
We do not do "Managed Relations". You have to set your associations manually on both sides, just like you would have to do without using Hibernate. Just create an addB method with does that.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.