| Author |
When Session Closed Data Will be Lost in Hibernate
|
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
I develop application retrieve data and display data in JSP page.when I retrieve data and store the objects in a vector and put that vector to session then I closed the session.In JSP page I try to use that vector to get data but data will be lost.
I couldn't understand what is happening.Any body have idea about that problem.
Thanks
Sameera
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
What session are we talking about here? A Hibernate Session or an HttpSession?
Assuming its a Hibernate Session, closing the session will not empty the collection. Can we see your code?
(And why are you using a Vector? Do you need access to its contents to be synchronous?)
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
What session are we talking about here? A Hibernate Session or an HttpSession?
I am talking about hibernate session.
Can we see your code?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Like I said, closing the session will not empty your Vector. You must have some other issue. Do you fill it in the first place? Is anything returned by your HQL?
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
Do you fill it in the first place? Is anything returned by your HQL?
I couldn't understand above questions ? Can explain?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Does your query return any results?
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
|
Yes that query returns result.
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
Hi every one didnt get any solution still.
Please help me
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Can you post all your code? Where do works and worksh get declared?
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
Can you post all your code? Where do works and worksh get declared?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
There are only three reasons why the Vector would be empty:
An exception occursThe query returns nothingYour Session is null
Hibernate clears its Session when you close or flush it. It does not clear any other data unassociated with the Session.
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
No there is no any exception occur , query is result not empty , session is not null.I only did hibernate session closing then i cant get data on my JSP page through the http session when i didn't close the hibernate session i can get data.
This is the code i put vector in session :
Vector workdedails=wsb.getWorkSummery(wsfb.getEmployeeNumber(),sdate);
session=request.getSession();
session.setAttribute("workdedails",workdedails);
i am also couldn't understand what is happening?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Why is works defined outside your method? Are you expecting only one to ever be returned?
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
|
No any special reason i just declare work out side the method.Is there any problem?
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
This exception throw when i closed method i finally found.
No there is no any exception occur
sorry for before i said no any exception raised.
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:140)
at opro.worksheet.WorkSheet$$EnhancerByCGLIB$$5d8fdae2.getBugNumber(<generated>)
at opro.worksheet.WorkSummery.doTag(WorkSummery.java:25)
at org.apache.jsp.Worksheet_jsp._jspService(Worksheet_jsp.java:739)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
|
 |
Reehan Lalkhanwar
Ranch Hand
Joined: Jun 16, 2007
Posts: 106
|
|
Finally.
You seem to be accessing the WorkSheet.getBugNumber(). This has been given as a proxy by Hibernate, as the session is closed, this is as expected
You have to keep the session open.
|
Thank you,
Reehan
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Sameera Abeysekara Gunawardena wrote:No any special reason i just declare work out side the method.Is there any problem?
It means your Vector wil only ever have one entry. Is this what you want? And if so, why are you using a collection?
But this is an aside, your exception message tells you what real problem is.
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
It means your Vector wil only ever have one entry.
I cant understand what was told in above sentence.
Is this what you want?
I want close hibernate session when i open before i leave that code block to save memory
I use vector for store object.I can understand exception before you said like this.
Assuming its a Hibernate Session, closing the session will not empty the collection.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Sameera Abeysekara Gunawardena wrote:
It means your Vector wil only ever have one entry.
I cant understand what was told in above sentence.
My mistake - I'm missreading your code.
I want close hibernate session when i open before i leave that code block to save memory
You can't close the Session if you are using it.
|
 |
Reehan Lalkhanwar
Ranch Hand
Joined: Jun 16, 2007
Posts: 106
|
|
My suggestion would be at this point:
Instead of copying the element directly, make a copy of it into some other element.
Here in the constructor you can copy all the required fields to the new object.
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
You can't close the Session if you are using it.
Yes i know that. I mean after when i put all the objects in to vector returns by hibernate query.
i want close the session.If not how can i close that hibernate session?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Have a look at this.
|
 |
Sameera Abeysekara Gunawardena
Ranch Hand
Joined: Feb 22, 2007
Posts: 37
|
|
I got solution.I modify my code with above code line and assign value to inside the WorkSheet(WorkSheet obj) constructor now is work fine.
works = new WorkSheet( it.next());
Thanks for All
|
 |
 |
|
|
subject: When Session Closed Data Will be Lost in Hibernate
|
|
|