| Author |
issues with hibernate lazy settings
|
Priyanka Sumanam
Greenhorn
Joined: Aug 17, 2010
Posts: 25
|
|
Hi allm
I have a hbm as below
<hibernate-mapping>
<class name="au.gov.biosirt.bo.AoiSelectSetDetail" table="AOISELECTSETDETAIL" >
<id name="id" column="AOISELECTSETDETAILUFI" type="java.lang.String" unsaved-value="null" />
<many-to-one name="aoiSelectSet" column="AOISELECTSETUFI" class="au.gov.biosirt.bo.AoiSelectSet" />
<many-to-one name="aoi" column="AOIUFI" class="au.gov.biosirt.bo.Aoi" entity-name="Aoi" lazy="proxy"/>
<property name="aoiTargetPFI" type="java.lang.Long" />
<property name="aoiTargetDatasetId" type="java.lang.String"/>
</class>
</hibernate-mapping>
on calling session.merge() on the above class, lazy="poxy" on AOI is not working because the the lazy="false" setting on the mapping of the corresponding class as below
<hibernate-mapping>
<class name="au.gov.biosirt.bo.Aoi" table="aoi" lazy="false" entity-name="Aoi">
<id name="id" column="aoiufi" type="java.lang.String" unsaved-value="null" />
<property name="instanceId"/>
<property name="lastUpdatedDate"/>
<property name="lastUpdatedUserId"/>
|
|...
</class>
</hibernate-mapping>
I don't want to change the lazy fetching on the assosciated class to fix it.Is there any way around to avoid loading full AOI object on accesing AOISELECTSETDETAIL.
|
 |
Rishi Shehrawat
Ranch Hand
Joined: Aug 11, 2010
Posts: 218
|
|
|
Can you provide exception details & code snippet.
|
 |
Priyanka Sumanam
Greenhorn
Joined: Aug 17, 2010
Posts: 25
|
|
Hi Rishi,
I am not getting any exception.My concern is that, it is talking awful lot of time to load a list of AOISELECTSETDETAIL objects(am using session.load()) as it is fetching the associated AOI object as well which in turn have a lot of properties set to lazy="false".I have set lazy="proxy" on definition of property AOI in AOISELECTSETDETAIL hbm file.But still that is not taking effect as the whole AOI entity is set to lazy="false" in its hbm as i highlighted below.
I done want to change the lazy setting on the associated hbm.
So the question is is there any way to avoid loading the associated object irrespective of what is set at the entity level in its hbm.
I hope this is clear enough atleast this time.
|
 |
Rishi Shehrawat
Ranch Hand
Joined: Aug 11, 2010
Posts: 218
|
|
You can override if you are using Criteria.
http://community.jboss.org/wiki/AShortPrimerOnFetchingStrategies
However setting lazy=false for entity with associations is not recommended. The default should be lazy loading enabled, the operation that need a particular collection/assocaition should initialize the collection that is required.
|
 |
Priyanka Sumanam
Greenhorn
Joined: Aug 17, 2010
Posts: 25
|
|
Thanks for the reply Rishi.I can ovverride the fetchmode on the properties directly defined on the entitiy I am querying on.But the problem here is because of the settings on a associated entity of the current entity.
I will try to explain with simple terms.
Two entities A and B.
<hibernate-mapping>
<class name="A" table="A" >
<many-to-one name="b" column="BUFI" class="Bi" entity-name="B" lazy="proxy"/>
</class>
</hibernate-mapping>
Definition of entity B that is associated to class A is below
<hibernate-mapping>
<class name="B" table="B" lazy="false" entity-name="B">
</class>
</hibernate-mapping>
associated property B is set to lazy="proxy" which is not taking effect as B is set to lazy="false" at the entity level.
Now when i am trying to load entity A, i can override fetchmode of it's own associtions which is any way set to lazy="proxy".I don't have any problem here.
The issue is cant override fetch mode of entity B,i.e set at its entity level.
Well, due to certain reasons which are part of business logic, we have to set lazy="false" for B at entity level.
|
 |
 |
|
|
subject: issues with hibernate lazy settings
|
|
|