• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When Session Closed Data Will be Lost in Hibernate

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?)
 
Sameera Abeysekara Gunawardena
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your query return any results?
 
Sameera Abeysekara Gunawardena
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes that query returns result.
 
Sameera Abeysekara Gunawardena
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi every one didnt get any solution still.

Please help me
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post all your code? Where do works and worksh get declared?
 
Sameera Abeysekara Gunawardena
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can you post all your code? Where do works and worksh get declared?






 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are only three reasons why the Vector would be empty:
  • An exception occurs
  • The query returns nothing
  • Your 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
    Posts: 37
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Why is works defined outside your method? Are you expecting only one to ever be returned?
     
    Sameera Abeysekara Gunawardena
    Ranch Hand
    Posts: 37
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    No any special reason i just declare work out side the method.Is there any problem?
     
    Sameera Abeysekara Gunawardena
    Ranch Hand
    Posts: 37
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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)
     
    Ranch Hand
    Posts: 106
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 37
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 106
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 37
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 10336
    Hibernate Eclipse IDE Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Have a look at this.
     
    Sameera Abeysekara Gunawardena
    Ranch Hand
    Posts: 37
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    reply
      Bookmark Topic Watch Topic
    • New Topic