Hi (N)Hibernate Community,
As noted in the documentation, most relations (associations) in a DB schema are 1 to n.
That implies that every parent entity will get a collection of its children, if it is mapped into the OO world.
My first thought was that this would lead to a big object graph, mapping nearly the complete DB, if the the loaded object was the top-level object in the schema.
Fortunately, I discovered lazy loading and was happy. But when I played with a simple Parent/Child bidirectional association, I figured out that if I touch the collection of children in the parent object, all children are completely loaded.
I hoped defining the child object as proxy would change that behaviour, but it did not.
Well! Is it correct to define a proxy as lazy loading of a single object and a collection wrapper as lazy loading of a collection?
But it is not possible to have a collection of proxies where an access to a proxy leads to a DB fetch, which would mean, iterating a collection of n proxies would lead to n selects without batching?
And that functionality I wish to have is implemeted in H 3.1 (lazy="extra")?
That means one should touch the collection only if all objects are needed, otherwise it is better to use HQL.
But what are collections good for, if I cannot delete a child from the parent without loading, for instance, all the other 100000 children?
|