Toplink is optimized for caching, i.e. for the assumption that they won't need
to go to the database at all. Their assumption is that there is a very good
chance that your data has been previously fetched or created by the application
and when you navigate from Level1 to Level2 or down further, they will find all
related instances in the global (1 per PU) cache, clone them, and you'd be ready
to go much faster than actually doing a join on 3 tables and parsing the result.
HTH,
-marina
glassfish_at_javadesktop.org wrote:
> This is more exactly what I have (using cnnordins terminology):
>
> entity Level1
> Collection<Level2> level2s (oneToMany)
> String name;
>
> entity Level2
> Collection<Level3> level3s (oneToMany)
> Level1 parent (manyToOne)
> String name;
>
> entity Level3
> Level2 parent (manyToOne)
> String name;
>
> Lets say I have the following in the database tables:
> Level1: id,name
> 1, "myLevel1"
>
> Level2: id,parent_id references Level1(id),name
> 1, 1, "myFirstLevel2"
> 2, 1, "mySecondLevel2"
>
> Level3: id,parent_id references Level2(id),name
> 1, 1, "myFirstLevel3"
> 2, 1, "mySecondLevel3"
> 3, 2 "myThirdLevel3"
> 4, 2, "myFourthLevel3"
>
> All children collections are set to fetchtype.eager. If everything worked as I thought it would, toplink would produce an sql looking something like this, when getting the Level1 (id=1) object:
> select "*" from level1 t1 join level2 t2 on t1.id=t2.parent_id join level3 t3 on t3.id=t2.parent_id where t1.id=1
> resulting in:
> 1, "myLevel1",1, 1, "myFirstLevel2",1, 1, "myFirstLevel3"
> 1, "myLevel1",1, 1, "myFirstLevel2",2, 1, "mySecondLevel3"
> 1, "myLevel1",2, 1, "mySecondLevel2",3, 2 "myThirdLevel3"
> 1, "myLevel1",2, 1, "mySecondLevel2",4, 2, "myFourthLevel3"
> and from that build the level1 object with all its children.
>
> However, it doesn't. It simply makes one select for level1 and then one for each level2 object and then one for each level3 object. The same as if I use lazy where the childobjects will be fetched when accessing them.
>
> With the fetch join I can get Level1 with its child objects level2, but not deeper. Toplink will fetch the level3 children of level2 with one select each.
>
> If this is working as intended, how are one supposed to create tree structures with toplink without having to wait minutes for all the selects to be ready?
> [Message sent by forum member 'danielcroth' (danielcroth)]
>
> http://forums.java.net/jive/thread.jspa?messageID=226294
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>