I'm getting several times the same object when setting Fetchmode equals to Join on a object parent-childs relationship. Actually, for each child I'm getting a 'new' parent - with the same pointer -.
Parent has a collection of child (no join table). Due to the large amount of data (>1mio Parents, 20mio Childs) don't fetching would be very time consuming as for each parent (more or less) we're doing a request to the database.
Scrollable results is not supported with collection on 3.0.3
If somebody has some idea how to solve, bypass this, I would appreciate :
Mapping :
<hibernate-mapping package="model.contract">
<class name="Contract_CFL">
<id name="contractID" column="CONTRACT_ID">
<generator class="increment"/>
</id>
<set name="cashflows" lazy="false " cascade="all-delete-orphan">
<key column="CONTRACT_ID"/>
<one-to-many class="ContractCashflow_CFL"/>
</set>
<property name="bookValueDate" type="timestamp" column="BOOK_VALUE_DATE"/>
<property name="contractDealDate" type="timestamp" column="CONTRACT_DEAL_DATE"/>
<property name="fxRateAtCDD" column="FX_RATE_AT_CCD"/>
<property name="fxRateAtBVD" column="FX_RATE_AT_BVD"/>
<property name="sourceSystemName" column="SOURCE_SYSTEM_NUMBER"/>
<many-to-one name="contractCurrency" class="ch.iris.riskpro.tng.model.market.Currency" lazy="false" column="CONTRACT_CURRENCY"/>
</class>
<class name="ContractCashflow_CFL" table="CONTRACT_CFL_CASHFLOW">
<id name="id" column="ID">
<generator class="increment"/>
</id>
<property name="amount" column="AMOUNT"/>
<property name="date" column="AMOUNT_DATE"/>
</class>
</hibernate-mapping>
Code :
Load all data in packets of size bufferSize :
session.clear();
Criteria criteria = session.createCriteria(Contract_CFL.class)
.setFirstResult(firstResult)
.setMaxResults(firstResult+bufferSize)
.setFetchMode("cashflows", FetchMode.JOIN)
;
List list = criteria.list();
iter = list.iterator();
listSize = list.size();
I'm not sure if with this large amoung of data this is a good strategy (how efficient is setFirstResult()/setMaxResult() ?
When Run ...
currentResults: java.util.List = {java.util.ArrayList@2083} size = 50
[0] = {ch.iris.riskpro.tng.model.contract.Contract_CFL@2113}
[1] = {ch.iris.riskpro.tng.model.contract.Contract_CFL@2113}
[2] = {ch.iris.riskpro.tng.model.contract.Contract_CFL@2113}
....
[13] = {ch.iris.riskpro.tng.model.contract.Contract_CFL@2114}
[14] = {ch.iris.riskpro.tng.model.contract.Contract_CFL@2114}
[15] = {ch.iris.riskpro.tng.model.contract.Contract_CFL@2114}
The result is fine if I don't use Fetchmode.JOIN.
Cheers
|