Re: lazy materialization problem

2005-04-29 Thread Maksimenko Alexander
I'm using 1.0.3 version and default (per broker) cache
yes persistence broker wich fetch folder is different from that one wich 
materialize children.
So to prevent this I need touch all objects in single persistence broker 
(long-lived caches dont feet me because I'm using web application with 
many clients).
But I think its not good to iterate over the whole folder tree and touch 
every object because every touch is call to database.
If I cauld say OJB prefetch  parent and children reference in all 
folders wich I materizalize by this call it would be more productive

Clute, Andrew wrote:
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

 


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


RE: lazy materialization problem

2005-04-29 Thread Clute, Andrew

 If I cauld say OJB prefetch  parent and children 
 reference in all folders wich I materizalize by this call it 
 would be more productive
 

I am slightly confused by this statement. Are you saying you want all
the children to be materialized when the parent is created, thus
populating all of the children's back-references to it's parent with the
same instance? If so, how is what you are asking for different than just
setting the collection of children not to be a proxy collection?

The problem you are experiencing is something that we would like to fix,
so I would love to hear any, and all suggestions on work arounds for it.
But I am having trouble understanding what exactly your solution is.

On a side note: One quick, dirty, workaround is to save your 'folder'
object inside the new PersistenceBroker before calling any method on the
children collection to make it be materizalized. This will 1) save the
object to the DB, but 2) Place that object in the cache, so the same
reference will be used for your back-references. Now, this might not
work in your scenario, especially if your 'folder' object has been
mutated, and you are not ready to persist it yet. However, just a
thought.

-Andrew



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



Re: lazy materialization problem

2005-04-29 Thread Maksimenko Alexander
Clute, Andrew wrote:
If I cauld say OJB prefetch  parent and children 
reference in all folders wich I materizalize by this call it 
would be more productive

I am slightly confused by this statement. Are you saying you want all
the children to be materialized when the parent is created, thus
populating all of the children's back-references to it's parent with the
same instance? 

yes! That what I want.
In many cases proxies are well. In 99% i load only one folder, 
somethimes view its children or parent. So this problem in 99% doesn't 
bother me.
But only for one particular case I need work with the whole tree. So I 
want to change proxy attribute only for for this case when I want load 
the whole folders tree. Is it possible?


On a side note: One quick, dirty, workaround is to save your 'folder'
object inside the new PersistenceBroker before calling any method on the
children collection to make it be materizalized. This will 1) save the
object to the DB, but 2) Place that object in the cache, so the same
reference will be used for your back-references. Now, this might not
work in your scenario, especially if your 'folder' object has been
mutated, and you are not ready to persist it yet. However, just a
thought.
-Andrew
 


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


RE: lazy materialization problem

2005-04-29 Thread Clute, Andrew

 
 If I cauld say OJB prefetch  parent and children 
 reference in all folders wich I materizalize by this call 
 it would be 
 more productive
 
 I am slightly confused by this statement. Are you saying you 
 want all 
 the children to be materialized when the parent is created, thus 
 populating all of the children's back-references to it's parent with 
 the same instance?
 
 
 yes! That what I want.
 In many cases proxies are well. In 99% i load only one 
 folder, somethimes view its children or parent. So this 
 problem in 99% doesn't bother me.
 But only for one particular case I need work with the whole 
 tree. So I want to change proxy attribute only for for this 
 case when I want load the whole folders tree. Is it possible?
 


Yeah, take a look at:

http://db.apache.org/ojb/docu/guides/metadata.html#Per+thread+metadata+c
hanges

The basic concept is that you can get a copy of the
DescriptorRepository, and then get the ClassDescriptor for your 'folder'
object, and then get the CollectionDescriptor for your 'children'
collection. Then CollectionDescriptor#setLazy(false) for the duration of
your call, and then set it back.

Make sure to read about doing MetaData changes per Thread -- otherwise
your changes will affect the entire application, and not just this
particular instance (all instance of that collection will be loaded, not
just the one you care about).

Hope this helps.

-Andrew 


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



Re: lazy materialization problem

2005-04-29 Thread Maksimenko Alexander
Thanks Andrew!
That's what I need ;)
If I cauld say OJB prefetch  parent and children 
reference in all folders wich I materizalize by this call 
   

it would be 
   

more productive
   

I am slightly confused by this statement. Are you saying you 
 

want all 
   

the children to be materialized when the parent is created, thus 
populating all of the children's back-references to it's parent with 
the same instance?

 

yes! That what I want.
In many cases proxies are well. In 99% i load only one 
folder, somethimes view its children or parent. So this 
problem in 99% doesn't bother me.
But only for one particular case I need work with the whole 
tree. So I want to change proxy attribute only for for this 
case when I want load the whole folders tree. Is it possible?

   


Yeah, take a look at:
http://db.apache.org/ojb/docu/guides/metadata.html#Per+thread+metadata+c
hanges
The basic concept is that you can get a copy of the
DescriptorRepository, and then get the ClassDescriptor for your 'folder'
object, and then get the CollectionDescriptor for your 'children'
collection. Then CollectionDescriptor#setLazy(false) for the duration of
your call, and then set it back.
Make sure to read about doing MetaData changes per Thread -- otherwise
your changes will affect the entire application, and not just this
particular instance (all instance of that collection will be loaded, not
just the one you care about).
Hope this helps.
-Andrew 

-
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]


Re: lazy materialization problem

2005-04-28 Thread Martin Kalén
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].
If your problem is that from child=parent you don't get the 1:1 mapping
you would like, could you please tell us the details of your repository file?
I guess from your text that you want:
 a) for parent class, to map children with collection-descriptor and inverse FK
 b) for child class, to map parent with reference-descriptor and FK
On a, ie parent=child and Collection, you might want to use an ordered 
collection
as collection class and set orderby and sort attributes in order to get
deterministic ordering of the collection (if not, you will get RDBMS ordering =
random and likely to change on insert/update/delete on the table even if you
use an ordered Java collection as collection-class).
Please get back with more details if I didn't understand your question.
Regards,
 Martin
[1] 
http://db.apache.org/ojb/docu/guides/repository.html#collection-descriptor-N10611
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: lazy materialization problem

2005-04-28 Thread Maksimenko Alexander
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]


RE: lazy materialization problem

2005-04-28 Thread Clute, Andrew
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]



lazy materialization problem

2005-04-27 Thread Maksimenko Alexander
Hi!
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?

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