-->
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: Tomcat, Struts, and JDBCException
PostPosted: Wed Jan 14, 2004 6:08 pm 
Beginner
Beginner

Joined: Tue Jan 06, 2004 4:51 pm
Posts: 48
Hi,

I'm using the struts plug-in for hibernate 2.1 in Tomcat 5. So far it's worked pretty well, except I'm having this problem:

Code:
ERROR net.sf.hibernate.util.JDBCExceptionReporter --
Could not execute query
org.postgresql.util.PSQLException: Connection is closed.  Operation is not permi
tted.
        at org.postgresql.core.QueryExecutor.executeV3(QueryExecutor.java:116)


I have a general parent object that is inherited by several objects that looks like:
Code:
/*
* HSObjectManager.java
*
* Created on January 9, 2004, 12:48 PM
*/

package com.cc;

import net.sf.hibernate.FetchMode;
import net.sf.hibernate.FlushMode;
import net.sf.hibernate.LockMode;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.cfg.Environment;
import net.sf.hibernate.expression.Example;
import net.sf.hibernate.expression.Expression;
import net.sf.hibernate.expression.MatchMode;
import net.sf.hibernate.type.Type;

import java.util.Properties;
import java.io.FileInputStream;

import javax.naming.InitialContext;

/**
* Hibernate-Struts Object Manager, in general.
* Meant to be inherited.
* @author  dtam
*/
public class HSObjectManager {
   
    protected InitialContext ctx = null;
    protected SessionFactory sf = null;
    protected Session session = null;
    protected Transaction tx = null;
   
    protected static String sessionFactoryLookupName;
    protected static final String propertiesFileName = "tss.properties";
    protected static final String sessionFactoryLookupNameKey = "sessionFactoryLookupName";
   
    /** Creates a new instance of HSObjectManager */
    protected HSObjectManager() throws Exception {
        init();
    }
   
    protected void init() throws Exception {
        Properties p = new Properties();
        try {
            if (sessionFactoryLookupName == null) {
                p.load(new FileInputStream(propertiesFileName));
                sessionFactoryLookupName = p.getProperty(sessionFactoryLookupNameKey);
            }
        } catch (Exception e) {
            sessionFactoryLookupName = "tss:/SessionFactory";
        }
       
        ctx = new InitialContext();
        sf  = (SessionFactory) ctx.lookup(sessionFactoryLookupName);
        session = sf.openSession();
    }
           
    protected void finalize() throws Exception {
        session.close();
    }
}


so, for example, an action would instatiate a new WhateverHSObjectManager (which extends HSObjectManager) and the try something like:

Code:
    public Study getStudyByNumber(int number) {
        List result;
        try {
            result = session.find(
                "from Study as study " +
                "where study.number = ?",
                new Integer(number),
                Hibernate.INTEGER
                );
        } catch (Exception e) {
            log.debug("Can't retrieve number. Invalid number: " + number, e);           
            return null;
        }
       
        return (Study)result.get(0);       
    }


Which seems to be okay for the first action, but the next action it will return that error.


Top
 Profile  
 
 Post subject: REALLY wierd
PostPosted: Wed Jan 14, 2004 6:46 pm 
Beginner
Beginner

Joined: Tue Jan 06, 2004 4:51 pm
Posts: 48
Okay, i did some debugging, and right before the call where I get the

Caused by: org.postgresql.util.PSQLException: Connection is closed. Operation is not permitted.

error, I call

session.isOpen()
session.isConnected()

and they both return true. mmrh..


Top
 Profile  
 
 Post subject: More info
PostPosted: Wed Jan 14, 2004 7:04 pm 
Beginner
Beginner

Joined: Tue Jan 06, 2004 4:51 pm
Posts: 48
Hi,

I just tried both:

Code:
session.disconnect();
session.reconnect();


and

Code:
session.close();
init();


before the session.find, but no dice.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 3:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The underlying connection is closed, apparently with no relation to Hibernate, do you use a connection pool ? You should, it kind of it's job.

_________________
Emmanuel


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.