-->
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.  [ 41 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: could not initialize proxy - the owning Session was closed
PostPosted: Thu Oct 27, 2005 12:08 pm 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
Hello,

I have everything in my mappings set to lazy="false", everything. Now i still get proxy instances giving me trouble after session is closed.

all my refs look like
<many-to-one lazy="false" fetch="join"
name="schaduwRekening"
class="****"
column="***"
outer-join="true"
/>

all sets look like
<set lazy="false" name="***" table="***" schema="**" >
<key column="***"/>
<many-to-many column="***" class="***"/>
</set>

all class tags look like
<class name="***" table="TB150_OEH" schema="BU" >

Code:
javax.servlet.jsp.JspException: ServletException in '/WEB-INF/***/***.jsp': could not initiali
ze proxy - the owning Session was closed
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:923)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)
   at com.ibm._jsp._layout._jspx_meth_tiles_insert_2(_layout.java:413)
   at com.ibm._jsp._layout._jspService(_layout.java:156)
   at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:88)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1282)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:673)
   at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:117)
   at com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.handleRequest(JSPExtensionServletWrapper.java:178)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:265)
   at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
   at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
   at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:239)
   at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:302)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1282)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:673)
   at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2905)
   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:1829)
   at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:84)
   at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:469)
   at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:408)
   at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:101)
   at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:566)
   at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:619)
   at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:952)
   at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1039)
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1455)


Needles to say that it is driving me nuts. Any help is highly appreciated.


Top
 Profile  
 
 Post subject: another trace
PostPosted: Thu Oct 27, 2005 12:14 pm 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
the previous trace had no hibernate elements this one has
Code:
[27-10-05 17:58:41:161 CEST] 00000048 ServletWrappe E   SRVE0014E: Uncaught service() exception root cause /WEB-INF/***.jsp: org.hibernate.LazyInitializationException: could not initialize proxy - the owning Se
ssion was closed
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
   at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
   at nl.***.data.rekening.VerzamelRekening$$EnhancerByCGLIB$$ad880c3d.getNr(<generated>)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
   at java.lang.reflect.Method.invoke(Method.java:391)
   at org.apache.commons.el.ArraySuffix.evaluate(ArraySuffix.java:314)
   at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
   at org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
   at org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
   at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:720)
   at com.ibm._jsp._raadplegenSSPRekening._jspx_meth_c_if_7(_raadplegenSSPRekening.java:1264)
   at com.ibm._jsp._raadplegenSSPRekening._jspService(_raadplegenSSPRekening.java:189)
   at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:88)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1282)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:673)
   at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:117)
   at com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.handleRequest(JSPExtensionServletWrapper.java:178)
   at com.ibm.ws.jsp.webcontainerext.JSPExtensionProcessor.handleRequest(JSPExtensionProcessor.java:241)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.include(WebAppRequestDispatcher.java:501)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:1034)
   at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:476)
   at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:99)
   at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:135)
   at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:760)
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:892)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:462)
   at com.ibm._jsp._layout._jspx_meth_tiles_insert_2(_layout.java:413)
   at com.ibm._jsp._layout._jspService(_layout.java:156)
   at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:88)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1282)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:673)
   at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:117)
   at com.ibm.ws.jsp.webcontainerext.JSPExtensionServletWrapper.handleRequest(JSPExtensionServletWrapper.java:178)
   at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:265)
   at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
   at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
   at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:239)
   at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:302)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1282)
   at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:673)
   at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2905)
   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:1829)
   at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:84)
   at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:469)
   at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:408)
   at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:101)
   at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:566)
   at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:619)
   at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:952)
   at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1039)
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1455)



Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 11:54 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
friend,
this is due to the way hibernate works.
this exception occurs when you try to access LINKED (remember relationships) object's properties. You could still access its primary key value, not if u try to access OBJECT's properties, u would get this exception.

How to solve?
You need to open session as soon request comes and close it when response is delivered
Or You need to use DTO and populate it with all the values while your session is still valid in ur service object. Again, as you close your session as service layer, your returned entity object would have links to its child/parent, but if u ever try to access properties other than LINKED one, u would get the exception

Got????


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 12:00 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Friend,
Read this. You would get very clear idea why u get this exception.
http://www.hibernate.org/43.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 3:30 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
arumugam_kasi wrote:
Friend,
Read this. You would get very clear idea why u get this exception.
http://www.hibernate.org/43.html


Friend,

Thanks for your reaction but I already understood WHY i get the exception. The thing is that theoritically I should be able to configure hibernate so that it does not use proxies but whatever I do those proxies just won't go away. What I am wondering why is the fact that I cannot select stuff outside of a session context, what is the danger? Now I have to refactor my whole application because of this, great! I am actually forced to use hibernate for my work, I am more a fan of OJB that is sooo much easier to work with, OJB doesn't have a session context, why is hibernate so rigid about this, I really don't understand.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 4:34 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
for sake of time I am now trying to call all needed fields in my DAO while the session is still open. When i break with the debugger I can see the value og the property i need.

eg in my DAO i call

person.getAddress().getZip();

This would make the proxy load stuff shouldn't it? Now in my JSP i do

${person.address.zip} but still this doesn't work.

I tried opening a session before forwarding to my JSP, still doesn't work. I am on this for days now trying to display a simple property on a JSP page. I never lost so much time on such a simple task, that fact alone indicates that some relaxation is needed this area. I read the docs stating that I might not see updates that occured in the time between session closement and rendering in the JSP, come on give me a break, the rendering takes place maybe 1 millisecond after the session closes. If something did changed in that 1 millisecond then that is fine by me. At least give us developers the change to take this "really dangereous risk". It is nice to be protected against myself but it can be overdone also and then it turns into rigidness wich is IMHO the case here.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 4:41 am 
Beginner
Beginner

Joined: Tue Aug 16, 2005 3:58 am
Posts: 40
Location: Singapore
Friend,
Understand this!!!
You must use a single session throughout your single request to solve this problem.

You know why?
By the time you close your session in DAO, Hibernate forgets about your relatioship or forced to.
When the loaded/selected object is returned to JSP via Controller, it would have lost all hibernate provided links/associations. So you simply cannot lookup values for fields in JSP.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 4:54 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Or you could create a Data Transfer Object loaded with all data needed for that view and use that in the view.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 6:50 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
arumugam_kasi wrote:
Friend,
Understand this!!!
You must use a single session throughout your single request to solve this problem.

You know why?
By the time you close your session in DAO, Hibernate forgets about your relatioship or forced to.
When the loaded/selected object is returned to JSP via Controller, it would have lost all hibernate provided links/associations. So you simply cannot lookup values for fields in JSP.


Friend,

Thank you again for your reaction but again I have to ask WHY do I still get a proxy object when I set everything to NOT LOAD LAZY. In a JTA environment it is not that easy to do as you suggest. And that is not the issue anyway. I think the way it works in hibernate now is extremely tedious. Other solution don't have this "problem" and they also work. I think this is a really really bad design desicion. Once again I know what is going on and I understand the concept but I want to be able to work without proxies and hibernate does not seem to offer that in spite of the fact that they claim so according to the docs. The attribute lazy="false" does not seem to have any effect whatsoever.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 6:57 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
jamie_dainton wrote:
Or you could create a Data Transfer Object loaded with all data needed for that view and use that in the view.


Thanks for the suggestion, it is the road i am following now. But tell me, how crappy is this on a scale from 1 to 10, i'd say 11. Really that is just a very ugly workaround for something so basic. I am greatly disappointed in hibernate that i have to go trough all this nonsense.

Once again thanks for the responses, I really appreciate that!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 6:59 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
This may also help if you haven't seen it already.

http://www.hibernate.org/43.html


It illustrates the open in view pattern.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 7:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
How crappy is it that people use tools (freely available I might add) and then bash those tools because they do not understand how to properly use those tools? Fairly crappy I'd say; maybe even 12 on your scale of 10...

Quote:
In a JTA environment it is not that easy to do as you suggest

Um, yes it is that easy. Scope the session to the JTA transaction such that the same session is available throughout the duration of that JTA transaction. Or you know what, even use the built-in capability of Hibernate doing this for you (SessionFactory.getCurrentSession()).

Or yeah, go ahead and make eveything non-lazy (maybe try reading the docs as to the correct way to do that) and suck most of your database into memory just to load in some single row of data.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 7:33 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
steve wrote:
How crappy is it that people use tools (freely available I might add) and then bash those tools because they do not understand how to properly use those tools? Fairly crappy I'd say; maybe even 12 on your scale of 10...

Quote:
In a JTA environment it is not that easy to do as you suggest

Um, yes it is that easy. Scope the session to the JTA transaction such that the same session is available throughout the duration of that JTA transaction. Or you know what, even use the built-in capability of Hibernate doing this for you (SessionFactory.getCurrentSession()).

Or yeah, go ahead and make eveything non-lazy (maybe try reading the docs as to the correct way to do that) and suck most of your database into memory just to load in some single row of data.


Hey finally a discussion, and also speaking my language. Your argument about something being free doesn't mean anything to me since I did not made the decision to use it. And I find it a weak argument also.

I agree that making everything non-lazy is not the way. But shouldn't it at least work that way if I want it to work that way? The database is not and wil not be that big and with a cache behind I see no problems.

The JTA transaction is finished before i get to the JSP so I don't see how that can workout for me.

All and all this is just non-intuitive and tedious, and I am not the only one because this is considered a pain by many. And if am the basher because it drives me nuts then so be it, fine.

I have hibernate in action on my desk for a while now. I browsed the online docs over and over but i am probably to stupid to understand it all. Strange though that I understand everything else out there.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 7:47 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
jamie_dainton wrote:
This may also help if you haven't seen it already.

http://www.hibernate.org/43.html


It illustrates the open in view pattern.


thanks i saw it but i have 12 more hours to finish my work before i leave my job and have no time to do refactoring of this kind. Please understand that I am working with existing stuff and solutions, it is not easy to oversee the consequences of adjustments in this area. The DAO's are wrapped in EJB's (not my decision) and I am forbidden to do anything with hibernate sessions outside the EJB context. My hands are tied behind my back as useual. That is why this is so frustrating, it is just to rigid for me and i don't see the need for this rigidness also. At least give us the possibilty to bypass this safety thing when I think it is approriate. Honestly I want to do code that myself but that doesn't help me out now.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 8:19 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
See "Hibernate.initialize()", It must be a good compromise.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 41 posts ]  Go to page 1, 2, 3  Next

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.