-->
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: About Hibernate cache
PostPosted: Mon Oct 04, 2004 9:08 am 
Newbie

Joined: Sun Sep 26, 2004 8:56 am
Posts: 3
In setting a bidirectional assoiation, for example Child/Parent relation, if only set one direction:

child.setparent(parent) // leave out code: parent.addchild(child)
session.save(child)

Then retrieve the assoiation:

child.getParent() is OK

parent.getChildren() is empty.

And the data in DB ,"parent_id" is correct.

But if close current session, and open a new seesion, parent.getChildren() returns is correct.

I think when the save operation is successful, Hibernate only update the

database,the other assoiation end in cache (first-level cache) is not

refreshed . It is the expected behavior??????

I have tried the session.get() and session.load(). They can not solve my problem. How can I synchronize the database and the cache????


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 04, 2004 10:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
I think when the save operation is successful, Hibernate only update the

database,the other assoiation end in cache (first-level cache) is not

refreshed . It is the expected behavior??????


yes it is!
this is your job to manage the java model integrity.
You have to explicitly set both ends of a bidirectional association.

There is a best practice described in Hibernate in action (just some smart code to add in the setter or addChild method)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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.