What version of OJB are you using (1.0, 1.0.2?), and which type of cache are 
you using? (ObjectCacheTwoLevel, ObjectCacheDefaultImpl)?

The issue stems from the fact that your proxy collection is being materialized 
with 1) a different PersistneceBroker instance then the parent object, and 2) 
You are using a cache implementation that either creates copies 
(ObjectCacheTwoLevel) or is short-lived (ObjectCachePerBroker).

This is a known issue, especially with all the cache implementations other than 
ObjectCacheDefault.

For instance, if you are using ObjectCacheTwoLevel, it guarantees detached 
objects from the application cache, while guaranteeing the same reference for 
logically identical objects, but only for the life of the PersistenceBroker. 
So, if the parent object is created in one PB instance, and the collection 
proxy is materialized in another PB instance, you will get different references 
for your 'folder' object.

Can you tell me a little bit more about your application: Is this a web app? 
What is the lifecycle for your PersistenceBrokers (do you use one for each 
action? Keep one open for the entire request?). Does the materlization of our 
parent 'folder' object happen in the same request as when the collection proxy 
is 'touched' and forced to be materialized?

-Andrew







> -----Original Message-----
> From: Maksimenko Alexander [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, April 28, 2005 8:03 AM
> To: OJB Users List
> Subject: Re: lazy materialization problem
> 
> Martin Kalén wrote:
> 
> > Maksimenko Alexander wrote:
> >
> >> I have tree like structure (with parent,children 
> relationships). I'm 
> >> using proxies to lazy materialize them. Everything works 
> well but in 
> >> particular cases I have to materialize the whole tree because
> >> folder.getChildren().get(0).getParent() is not the same as 
> folder and 
> >> sometimes it makes the problem. How can I tell OJB to prefetch 
> >> references "parent" and "children" for all folders? Or is there 
> >> simpler way to do this?
> >
> >
> > I am not sure I understand your question correctly, but it 
> sounds like
> > you (possibly among other things) are interested in getting a 
> > deterministic
> > order on your Collection references?
> >
> > If that is the case, have a look at the orderby and sort attributes
> > of collection-descriptor [1].
> 
> Sory a was not clear enough :(
> No I mean that due lazy initialization folder and 
> folder.getChildren().get(0).getParent() are equals (by id) 
> but not the 
> same objects. Lets we have
> Folder folder = ...//get from ojb
> Folder child = folder.getChildren().get(0);
> folder.changeName("new-name") // but 
> child.getParent().getName() doesn't 
> equal "new-name"
> 
> its okey in the most cases but in only one case I need 
> prevent this. I 
> think this problem will disapear if I can tell ojb don't use 
> proxies for 
> particular getting objects from database. but I don't know 
> how I can do this
> Hope I was clear now ;)
> Thanks
> Alexander
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to