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.