-->
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.  [ 4 posts ] 
Author Message
 Post subject: jsp view error when session.close()
PostPosted: Wed May 05, 2010 1:43 pm 
Newbie

Joined: Wed Mar 03, 2010 6:27 am
Posts: 11
Hi all,
I got a problem since 3 months and couldnt solve it yet.
The porblem is that;
When I close hibernate session after getting ant value and then show it in jsp page, it doesnt work,
but if I get the value first and view it in jsp, then close the hibernate session, it works fine.

Ofcourse this method is too hard to follow all codes.
I want to close hibernate session in each method (that shoud be standard).

How can I solve this problem?
If I use fetch = false or true that is a bad way too.
Can anyone help ?
Thanks...


Top
 Profile  
 
 Post subject: Re: jsp view error when session.close()
PostPosted: Thu May 06, 2010 5:03 am 
Newbie

Joined: Wed Mar 03, 2010 6:27 am
Posts: 11
Any suggesstion ?


Top
 Profile  
 
 Post subject: Re: jsp view error when session.close()
PostPosted: Thu May 06, 2010 8:32 am 
Newbie

Joined: Wed Mar 03, 2010 3:36 am
Posts: 5
If you give the code snap then that would be helpful and
one thing are you accessing that value directly from session ?


Top
 Profile  
 
 Post subject: Re: jsp view error when session.close()
PostPosted: Thu May 06, 2010 10:48 am 
Newbie

Joined: Wed Mar 03, 2010 6:27 am
Posts: 11
Code:
public class HibernateUtil {

    private static final SessionFactory sessionFactory;
   

    static {
        try {

            sessionFactory = new Configuration().configure().buildSessionFactory();

        } catch (Throwable ex) {

            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
   



    public static Session getSession() throws HibernateException {
        return sessionFactory.openSession();
    }

}

Code:
public ArrayList getRecents() {
        try {
            session = HibernateUtil.getSession();
            this.videoList.clear();
            Query med= session.createQuery("FROM Media m where m.fileName != :var1 ORDER BY m.id desc");
            med.setString("var1", "");

            session.flush();
            session.close()
        } catch (HibernateException ex) {
            System.out.println("HibernateException populateRecentVideos : " + ex);
            return null;
        }
        return med.list();;
    }


In here if I use session.close(), I cant view list at jsp, I have to close session after rendering that list at page.

But It is too difficult to follow all codes in a full web application.
So, I want to close it as I posted in that method.
What is the wrong?


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