I've read the documentation of hibernate and I found this:
"Sometimes we need to ensure that a proxy or collection is initialized
before closing the Session. Of course, we can alway force
initialization by calling cat.getSex() or cat.getKittens().size(), for
example. "
My questions are:
0. From the above statement, does it means when I call load(SomeClass.class) to get all data even though lazy=true, and I call size() method over the lazy collection (e.g. 1 million rows), then the whole data (1 million rows) will be initialized? Isn't it so much for
retrieving size of collection.
1. When it is specified lazy=true, collection retrieval by select query nor doing filter(SomeClass.class) then list() nor by getChildren() (one to many assoc) won't initialize the collection after the call of size() over the collection, right?
2. Is it okay if I call load(SomeClass.class) to get list of all records even though I just want to show some rows? Does Hibernate have default batch size that suitable for paging problem?
e.g. when I do batch=10 then do filter(SomeClass.class).list(), Hibernate just populate 10 rows into the (hibernate own implementation) collection? But, when we call coll.get(14), the hibernate will select next 10 rows. Am I right?
I'm still searching for best efficiency in hibernate. I hope you have time to answer my questions or give any references.
Thanks in advance.
|