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.  [ 1 post ] 
Author Message
 Post subject: HibernateUtil (from CaveatEmptor) updated for Hibernate 3
PostPosted: Mon Apr 25, 2005 4:40 pm 
Regular
Regular

Joined: Tue Nov 30, 2004 4:23 pm
Posts: 62
If I wanted to utilize the HibernateUtil class from CaveatEmptor with Hibernate 3, is there any additional logic that is required except for changing the library names?

The reason I ask is that within my DAO, I call the getSession with the following code:
Code:
        List goalsList;
        Session session = HibernateUtil.getSession();
        Query query = session.getNamedQuery("selectGoals");
        query.setInteger("taskId", taskId);
        query.setString("timeframe", goalType);
        goalsList = query.list();
        session.close();
        return goalsList;


This causes an exception to be thrown that the Session is already closed.

Quote:
5 threw exception: org.hibernate.HibernateException: Session is closed
org.hibernate.HibernateException: Session is closed
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:97)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:86)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1096)
at org.hibernate.loader.Loader.doQuery(Loader.java:367)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:208)
at org.hibernate.loader.Loader.doList(Loader.java:1522)
at org.hibernate.loader.Loader.list(Loader.java:1505)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:103)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1343)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:151)


But if I utilize the following code in my DAO, the query works without problems

Code:
        List goalsList;
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session session = sf.openSession();
        Query query = session.getNamedQuery("selectGoals");
        query.setInteger("taskId", taskId);
        query.setString("timeframe", goalType);
        goalsList = query.list();
        session.close();
        return goalsList;


Thanks for your help!

-jay


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.