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.  [ 2 posts ] 
Author Message
 Post subject: LazyInitializationException??
PostPosted: Mon Jun 18, 2007 6:01 am 
Newbie

Joined: Mon Jun 18, 2007 5:21 am
Posts: 1
Location: France
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:

<hibernate-mapping package="com.ibm.dolphin.hibernate.bean">
<class
name="NaduRecipient"
table="NADU_RECIPIENT"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
type="string"
column="ADRESS"
>
</id>

<property
name="Role"
column="ROLE"
type="string"
not-null="false"
length="30"
/>
<property
name="Name"
column="NAME"
type="string"
not-null="false"
length="50"
/>
<many-to-one
name="Type"
column="TYPE"
class="TypeNadur"
not-null="true"
fetch="join"
outer-join="true"
lazy="false"
>
</many-to-one>

</class>
</hibernate-mapping>

--------------------------------------------

<hibernate-mapping package="com.ibm.dolphin.hibernate.bean">
<class
name="TypeNadur"
table="TYPE_NADUR"
lazy="false"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
type="string"
column="TYPE"
>
</id>

<set name="NaduRecipients" cascade="all" inverse="true" lazy="false">
<key column="TYPE"/>
<one-to-many class="NaduRecipient"/>
</set>

<set
name="NADUs"
table="MAILING_NADU"
cascade="all"
>
<key column="TYPE"/>
<many-to-many column="NADU" class="Nadu"/>
</set>

</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:

[18/06/07 11:18:14:949 CEST] 00000028 SystemOut O [HibernateAdapter:INFO] Hibernate SessionFactory built from Configuration :: [org.hibernate.impl.SessionFactoryImpl@3c7f21cb]
[18/06/07 11:18:16:081 CEST] 00000028 SystemOut O Hibernate: select nadurecipi0_.ADRESS as ADRESS11_, nadurecipi0_.ROLE as ROLE11_, nadurecipi0_.NAME as NAME11_, nadurecipi0_.TYPE as TYPE11_ from ROUEL.NADU_RECIPIENT nadurecipi0_
[18/06/07 11:18:16:281 CEST] 00000028 SystemOut O [DynaQuery:INFO] query result:
[com.ibm.dolphin.hibernate.bean.NaduRecipient@9429469a, com.ibm.dolphin.hibernate.bean.NaduRecipient@75e21d7d, com.ibm.dolphin.hibernate.bean.NaduRecipient@e235ec7d, com.ibm.dolphin.hibernate.bean.NaduRecipient@7545bba7, com.ibm.dolphin.hibernate.bean.NaduRecipient@f6b681f8]
[18/06/07 11:18:16:552 CEST] 00000028 LazyInitializ E could not initialize proxy - the owning Session was closed
[18/06/07 11:18:16:562 CEST] 00000028 LazyInitializ E TRAS0014I: L'exception suivante a été consignée : org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:98)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:158)
at com.ibm.dolphin.hibernate.bean.TypeNadur$$EnhancerByCGLIB$$d90be396.toString(<generated>)
at freemarker.ext.beans.StringModel.getAsString(StringModel.java:99)
at freemarker.core.EvaluationUtil.getString(EvaluationUtil.java(Compiled Code))
at freemarker.core.Expression.getStringValue(Expression.java:108)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java(Inlined Compiled Code))
at freemarker.core.MixedContent.accept(MixedContent.java(Compiled Code))
at freemarker.core.Environment.visit(Environment.java(Compiled Code))
at freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:160)
at freemarker.core.Environment.visit(Environment.java:351)
at freemarker.core.IteratorBlock.accept(IteratorBlock.java:95)
at freemarker.core.Environment.visit(Environment.java(Inlined Compiled Code))
at freemarker.core.MixedContent.accept(MixedContent.java(Compiled Code))
at freemarker.core.Environment.visit(Environment.java(Compiled Code))
at freemarker.core.Environment.process(Environment.java:176)
at freemarker.template.Template.process(Template.java:232)
at com.ibm.dolphin.webengine.template.FreeMarkerEngine.write(FreeMarkerEngine.java:32)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderDecorators(TemplateEngine.java:352)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderUsingFilters(TemplateEngine.java:305)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderUsingCache(TemplateEngine.java:242)
at com.ibm.dolphin.webengine.viewcontroller.TemplateFunctions.includeTemplate(TemplateFunctions.java:111)
at com.ibm.dolphin.webengine.template.FreeMarkerEngine.renderChildTemplate(FreeMarkerEngine.java:48)
at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:616)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:113)
at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
at freemarker.core.Expression.getAsTemplateModel(Expression.java(Compiled Code))
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java(Inlined Compiled Code))
at freemarker.core.MixedContent.accept(MixedContent.java(Compiled Code))
at freemarker.core.Environment.visit(Environment.java(Compiled Code))
at freemarker.core.Macro$Context.runMacro(Macro.java:164)
at freemarker.core.Environment.visit(Environment.java:537)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:128)
at freemarker.core.Environment.visit(Environment.java(Inlined Compiled Code))
at freemarker.core.MixedContent.accept(MixedContent.java(Compiled Code))
at freemarker.core.Environment.visit(Environment.java(Compiled Code))
at freemarker.core.Environment.process(Environment.java:176)
at freemarker.template.Template.process(Template.java:232)
at com.ibm.dolphin.webengine.template.FreeMarkerEngine.write(FreeMarkerEngine.java:32)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderDecorators(TemplateEngine.java:352)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderUsingFilters(TemplateEngine.java:305)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderUsingCache(TemplateEngine.java:242)
at com.ibm.dolphin.webengine.viewcontroller.TemplateFunctions.includeTemplate(TemplateFunctions.java:111)
at com.ibm.dolphin.webengine.template.FreeMarkerEngine.renderChildTemplate(FreeMarkerEngine.java:48)
at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:616)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:113)
at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
at freemarker.core.Expression.getAsTemplateModel(Expression.java(Compiled Code))
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java(Inlined Compiled Code))
at freemarker.core.MixedContent.accept(MixedContent.java(Compiled Code))
at freemarker.core.Environment.visit(Environment.java(Compiled Code))
at freemarker.core.Macro$Context.runMacro(Macro.java:164)
at freemarker.core.Environment.visit(Environment.java:537)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:128)
at freemarker.core.Environment.visit(Environment.java(Inlined Compiled Code))
at freemarker.core.MixedContent.accept(MixedContent.java(Compiled Code))
at freemarker.core.Environment.visit(Environment.java(Compiled Code))
at freemarker.core.Environment.process(Environment.java:176)
at freemarker.template.Template.process(Template.java:232)
at com.ibm.dolphin.webengine.template.FreeMarkerEngine.write(FreeMarkerEngine.java:32)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderDecorators(TemplateEngine.java:352)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderUsingFilters(TemplateEngine.java:305)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderUsingCache(TemplateEngine.java:242)
at com.ibm.dolphin.webengine.viewcontroller.TemplateFunctions.includeTemplate(TemplateFunctions.java:111)
at com.ibm.dolphin.webengine.template.FreeMarkerEngine.renderChildTemplate(FreeMarkerEngine.java:48)
at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:616)
at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:113)
at freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
at freemarker.core.Expression.getAsTemplateModel(Expression.java(Compiled Code))
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java(Inlined Compiled Code))
at freemarker.core.MixedContent.accept(MixedContent.java(Compiled Code))
at freemarker.core.Environment.visit(Environment.java(Compiled Code))
at freemarker.core.Macro$Context.runMacro(Macro.java:164)
at freemarker.core.Environment.visit(Environment.java:537)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:128)
at freemarker.core.Environment.visit(Environment.java(Inlined Compiled Code))
at freemarker.core.MixedContent.accept(MixedContent.java(Compiled Code))
at freemarker.core.Environment.visit(Environment.java(Compiled Code))
at freemarker.core.Environment.process(Environment.java:176)
at freemarker.template.Template.process(Template.java:232)
at com.ibm.dolphin.webengine.template.FreeMarkerEngine.write(FreeMarkerEngine.java:32)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderDecorators(TemplateEngine.java:352)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderUsingFilters(TemplateEngine.java:305)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderUsingCache(TemplateEngine.java:242)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderUsingErrorHandler(TemplateEngine.java:123)
at com.ibm.dolphin.webengine.template.TemplateEngine.renderTemplate(TemplateEngine.java:53)
at com.ibm.dolphin.webengine.viewcontroller.ViewController.renderTemplate(ViewController.java:318)
at com.ibm.dolphin.webengine.servlet.DolphinServletUtil.processRequest(DolphinServletUtil.java:83)
at com.ibm.dolphin.webengine.lifecycle.plugins.DolphinViewPlugin.handleRequest(DolphinViewPlugin.java:73)
at com.ibm.dolphin.webengine.lifecycle.LifecycleManager.processLifecycleRequest(LifecycleManager.java:225)
at com.ibm.dolphin.webengine.servlet.DRLProxyServlet.service(DRLProxyServlet.java:90)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1681)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:94)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:601)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1332)
.
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed

Name and version of the database you are using: DB2 v8.1.7.445

The generated SQL (show_sql=true):

select nadurecipi0_.ADRESS as ADRESS11_, nadurecipi0_.ROLE as ROLE11_, nadurecipi0_.NAME as NAME11_, nadurecipi0_.TYPE as TYPE11_ from ROUEL.NADU_RECIPIENT nadurecipi0

----------------------------------------

Bonjour,
Lorsque j'essaie d'afficher le résultat de la table NADU_RECIPIENT dans un tableau, j'obtiens l'exception LazyInitializationException.
J'ai essayé de modifier le paramètre Lazy(true|false) dans mes 2 fichiers de mapping dans lequel il y a l'association, mais sans résultats.

Comme je suis débutant, je manque de connaissance sur le paramètre Lazy, j'ai pourtant chercher des infos sur le tuto et sur des forums, mais je n'arrive tjrs pas à résoudre ce problème.

J'espère que l'un de vous trouvera une solution...
Merci d'avance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 9:14 am 
Newbie

Joined: Mon Jun 18, 2007 5:10 am
Posts: 3
La lazy loading à "false" permet de dire "récupère moi les données uniquement lorsque j'en ai besoin" que tu peux traduire par "remplis moi ma référence uniquement lorsque je fais appel a mon getter (et pas lors de l'execution de la reqûete)".

Le problème, c'est que lorsque tu vas faire appel à ton getter, tu seras sorti du "scope transactionnel" d'hibernate, et du coup, tu ne pourras plus faire de requête "tardive".
Une solution : dans ta requete HQL, fais un "FROM NaduRecipient rec left join fetch rec.Type WHERE [tes éventuelles clauses where ici...]"
Problème : tu n'utilises plus le lazy loading là, étant donné que tu rempliras "tout le temps" ta référence (et non "juste quand tu en as besoin").
Pour une seule relation, c'est pas forcément dramatique ... maintenant si tu commences à avoir beaucoup de relations en cascades, tes temps de perfs vont se déteriorer ;)

Une autre solution : tu "synchronize" la durée de la session hibernate avec la durée de vie de ta request (mais attention, cela est très permissif ... on peut alors faire des requêtes un peu n'importe quand ..)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.