-->
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: General question regarding refresh & cascade
PostPosted: Thu Mar 26, 2009 4:09 pm 
Newbie

Joined: Thu Mar 26, 2009 3:31 pm
Posts: 2
Hi folks -
Can anyone give me some general advice on an issue I am having with the refresh function? Let me apologise in advance for not filling in the bullet points provided but my question is more of a general nature so it didn't seem helpful to post the versions etc which i am using.

To explain the issue, here's a simple example:
I have 2 classes: ClassA & Class B. ClassA has a list of ClassB's, which are defined as a one to many relationship (1 A to many B's). The list is mapped via a bag with cascade set to all. Both classes have their own tables in the database & ClassB's table has an additional column to hold the identifier of the class A which owns it.

Now, when i run my application and load an instance of ClassA (let's call it ObjectA), it loads all the instances of ClassB, which are associated with ObjectA, into the session as well. Similarly, if i call the refresh function on ObjectA, it cascades to all the associated ObjectB's and they refresh as well.

My issue is when something outside the hibernate session removes one of the objectB's (lets call the removed item ObjectB1) from the database. An example could be another user with another version of the application also working on a common database. When the first user then tries to refresh ObjectA, it still holds a memory reference to ObjectB1. It then tries to refresh ObjectB1 through the cascade, and throws a KeyNotFound exception because it is no longer in the database. I would have expected this to have returned an up to date version of ObjectA, with its list of ObjectB's minus the removed item, but obviously it doesn't..

So my question is this: How do you handle it? My first thought was to refresh each ObjectB seperately. This way i could catch the exception and easily remove the offending item from the session / application but this is essentially doing the cascade manually which defeats the point of using it. Secondly, the real life example is not as simple as this. In reality ObjectB has many ObjectC's which in turn have many ObjectD's and so on. Trying to do this manually would mean a hell of a lot of extra code.

Thanks in advance to anyone that can help, I've been hitting my head against this hibernate-shaped brick wall for a couple of days now lol


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 27, 2009 7:47 am 
Regular
Regular

Joined: Wed Feb 11, 2009 10:58 am
Posts: 55
Had a similar problem...

I had exactly the same scenario, but I didn't do Refresh but Update the deleted row... also got an exception.

Would be interesting if there's a general way how to deal with objects existing in the program but have been deleted from the database.

Hope anybody knows an answer other then just doing all the handling manually.

Thanks from my side, too.


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.