Since I migrate from Hibernate 2.1.7 to 3.1.3, I have problems with refresh.
I have noticed that refresh behavior have changed (migration note) :
- in 2.1.7, it refreshed only the object
- in 3.1.3, it refresh all the object graph
It seems that the refresh operate also on lazy collections even if they wasn't initialized before refresh. Is it normal ?
Here is my mapping :
Code:
...
<class table="TDPUDOSSIERDROIT" name="DossierDroit" lazy="false">
<id name="idDossierDroit" type="string">
<generator class="fr.dao.hibernate.HibernateUuidGenerator" />
</id>
<property name="dateDernierCalcul" type="timestamp" />
<set name="elementReference" lazy="true" sort="natural" inverse="true" cascade="all-delete-orphan">
<key column="idDossierDroit" />
<one-to-many class="ElementReference" />
</set>
</class>
<class table="TDPUELEMENTREFERENCE" name="ElementReference" lazy="false">
<id name="idElementReference" type="string">
<generator class="fr.dao.hibernate.HibernateUuidGenerator" />
</id>
<property name="campagne" type="int" />
<many-to-one name="dossierDroit" column="idDossierDroit" class="DossierDroit" not-null="true" />
</class>
...
My test :
Code:
DossierDroit dossier = (DossierDroit) this.getHibernateTemplate().load( DossierDroit.class, "02400002");
this.getHibernateTemplate().refresh(dossier);
And generated SQL (traces SQL hibernate) :
- Before refresh :
2007-01-22 16:26:03,421|DEBUG||select dossierdro0_.idDossierDroit as idDossie1_127_0_, dossierdro0_.dateDernierCalcul as dateDern2_127_0_ from TDPUDOSSIERDROIT dossierdro0_ where dossierdro0_.idDossierDroit=?
- After refresh :
2007-01-22 16:26:03,765|DEBUG||select dossierdro0_.idDossierDroit as idDossie1_127_1_, dossierdro0_.dateDernierCalcul as dateDern2_127_1_, elementref1_.idDossierDroit as idDossie3_3_, elementref1_.idElementReference as idElemen1_3_, elementref1_.idElementReference as idElemen1_121_0_, elementref1_.campagne as campagne121_0_, elementref1_.idDossierDroit as idDossie3_121_0_ from TDPUDOSSIERDROIT dossierdro0_ left outer join TDPUELEMENTREFERENCE elementref1_ on dossierdro0_.idDossierDroit=elementref1_.idDossierDroit where dossierdro0_.idDossierDroit=?
My problem is that for another object graph, refresh loads the whole database because all my objects are in relationship by traversing lazy loaded collections.
Is there a solution to refresh only the actual object on which I perform refresh and not collections as in Hibernate 2.1.7 ?
Thanks for your help.