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