I need to provide explanation why following code works well:
List<Child> dummyList = new ArrayList<Child>(); for(Parent parent : parents) { dummyList .addAll(parent.getChildren()); }
'Parent'-'Children' is mapped as
<bag name="children" cascade="all" batch-size="50" fetch="select"> <key column="PARENT_ID" foreign-key="FK_FFP_METADATA_FFP" /> <one-to-many class="Child" /> </bag> ------- In DAO layer, when line 'dummyList .addAll(parent.getChildren());' is executed, children collections for ALL parents are loaded (initialized). This is exactly what I want. ======================================= If, instead of 'addAll' I put following line: Hibernate.initialize(parent.getChildren()); there will be initialized children collection for single (current) parrent only. That is behavior I can expect.
Can someone explain why, in first case, 'children' collections are initialized for all 'parents' and not just current 'parent'?
Last edited by bjevta on Thu Dec 29, 2011 9:28 am, edited 1 time in total.
|