-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: lazy initialiaztion error using query cache
PostPosted: Thu Apr 12, 2007 11:11 pm 
Newbie

Joined: Thu Jan 18, 2007 12:55 am
Posts: 10
I have a unique problem. I am using ehcache for 2nd level caching. The following query joins the assosciation with the parent object.If i am not using queryCache i am able to access the assosociation withou any problem. If I use with query Cache enabled I get a lazy initization exception error when accessing the assosciation.

I have defined the echache.xml query cache region as this

<cache name="query.art1Cache" maxElementsInMemory="1000"
eternal="false" timeToLiveSeconds="86400" overflowToDisk="true" />

The question is why does it give lazy initialization error using query cache enabled and no error without query caching enabled.

Please help

[b]3.2[/b]

[b]Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping package="org.sae.model.article">
<class name="Article" table="ARTICLE" schema="DAILYMAG">
<cache usage="read-write"/>
<id name="articleId" type="java.lang.Long">
<column name="ARTICLE_ID" precision="18" scale="0" />
<generator class="sequence">
<param name="sequence">DAILYMAG.ARTICLE_SEQ</param>
</generator>
</id>
<set name="articleCompanies" inverse="true" lazy="true" >
<cache usage="read-write" />
<key>
<column name="ARTICLE_ID" precision="18" scale="0" />
</key>
<one-to-many class="ArticleCompany" />
</set>


</class>
</hibernate-mapping>

[/b]

[b]
session.setCacheMode(CacheMode.NORMAL)
Query queryObj = session.createQuery(
"select Article a left join fetch a.articleCompaies whre
a.articleId = ?");
query.setCacheable(true)
query.setCacheRegion("query.art1Cache);
List resultList = queryObj.list();
)
[/b]

[b]org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed[/b]

[bOrace 10G[/b]

[b]The generated SQL (show_sql=true):[/b]

[b]Debug level Hibernate log excerpt:[/b]


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 12, 2007 11:42 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi dangdunge,

Quick hack is to change this line
<set name="articleCompanies" inverse="true" lazy="true" >

to

<set name="articleCompanies" inverse="true" lazy="false" >

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 9:16 am 
Newbie

Joined: Thu Jan 18, 2007 12:55 am
Posts: 10
Thank you dharmendar for your input, My question is I am already loading all the assosciated graph with join fetcing, shouldn't it bring the main object and its assosciations. Or since when using ache results it will behave differently thatn normal query loading.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.