-->
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.  [ 3 posts ] 
Author Message
 Post subject: SQLException: No operations allowed after connection closed
PostPosted: Thu Mar 09, 2006 5:14 am 
Newbie

Joined: Thu Mar 09, 2006 4:57 am
Posts: 2
I was using default hibernate connection pool.After web server was started for about 8 hours or so I got the following exception :

java.sql.SQLException: No operations allowed after connection closed.

The I start using c3po connection pool.This problem was then solved.

But now sometimes the exception java.sql.SQLException: No operations allowed after connection closed has started to occur again.

This is full stack trace of exception :

java.sql.SQLException: No operations allowed after connection closed.
at com.mysql.jdbc.Connection.checkClosed(Connection.java:2785)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1354)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1335)
at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:190)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:396)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at _jsp._adsales._Sales._Inbox__jsp._jspService(adsales/Sales/Inbox.jsp:56)
at com.caucho.jsp.JavaPage.service(JavaPage.java:60)
at com.caucho.jsp.Page.pageservice(Page.java:570)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:159)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:267)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:388)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:490)
at com.caucho.util.ThreadPool.run(ThreadPool.java:423)
at java.lang.Thread.run(Thread.java:595)


This is my HibernateUtil.java Program :


package com.uniken.util;

import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;
import java.io.*;
import org.pf.file.*;

public class HibernateUtil
{
public static final SessionFactory sessionFactory;

static
{
try
{
// Create the SessionFactory
final Configuration cfg = new Configuration();

final Properties properties = new Properties();
properties.load(new FileInputStream(getHibernatePropertiesFile()));
cfg.setProperties(properties);
addDirectory(cfg, getHibernateDirectory(), true, new DefaultFilenameFilter("*.hbm.xml"));

sessionFactory = cfg.buildSessionFactory();

}
catch (Throwable ex)
{// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed. " + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal session = new ThreadLocal();

public static Session currentSession() throws HibernateException
{
Session s = (Session) session.get();
// Open a new Session, if this thread has none yet
if (s == null)
{
s = sessionFactory.openSession();
// Store it in the ThreadLocal variable
session.set(s);
}
return s;
}

public static void closeSession() throws HibernateException
{
Session s = (Session) session.get();
if (s != null)
s.close();
session.set(null);
}

public static void hibernateSetup() throws Exception
{
}

private static Configuration addDirectory(final Configuration configuration,
final File directory, final boolean recurse, final FilenameFilter filenameFilter)
throws IOException, MappingException
{
Configuration extendedConfiguration = configuration;
if (!directory.isDirectory())
{
throw new IOException("Passed file handle [" +
directory.getAbsolutePath() + "] is not a directory.");
}
final File[] files = directory.listFiles();
for (int index = 0; index < files.length; index++)
{
final File file = files[index];
if (recurse && file.isDirectory())
{
extendedConfiguration = addDirectory(extendedConfiguration,
file, recurse, filenameFilter);
}
else if (file.isFile() &&
filenameFilter.accept(directory, file.getName()))
{
extendedConfiguration = extendedConfiguration.addFile(file);
}
}
return configuration;
}

public static File getHibernateDirectory()
{
//System.out.println("HUtil path: " + new File("./s").getAbsolutePath());
return new File("webapps/wfs/hibernate");
}

public static File getHibernatePropertiesFile()
{
return new File(getHibernateDirectory(), "hibernate.properties");
}


}


This is one of JSP Pages I have used :


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="true"
import="com.uniken.util.*,com.uniken.adsalesentities.*,com.uniken.beans.*,com.uniken.beans.impl.*,org.hibernate.*,java.util.*"

%>

<%@ include file="../Functions_Common.jsp" %>

<%
String userid = (String)session.getAttribute("USERID");
String userrole = (String)session.getAttribute("USERROLE");
%>

<%
if (isLoggedIn(userid))
{
response.sendRedirect("../Login_Expired.jsp");
}
%>

<%
String inbox = request.getParameter("Inbox");
if( null != inbox )
{
session.removeAttribute("DOM");
session.removeAttribute("OP");
}
%>

<%
int PAGE_SIZE = 12;
int PAGE_START = 0;
int PAGE_END = 0;
int PAGE_NUMBER = 0;
int NO_OF_PAGES = 0;

if (null != request.getParameter("pageNum"))
{
PAGE_NUMBER = Integer.parseInt(request.getParameter("pageNum"));
}
else
{
PAGE_NUMBER = 1;
}
%>

<%
Session sess = HibernateUtil.currentSession();
Transaction tx = sess.beginTransaction();

PAGE_START = (PAGE_NUMBER-1)*(PAGE_SIZE);

Query qInbox = sess.createQuery("from " + WorkItem.class.getName() + " as c where c.ownerId = :userId order by lastModifiedTime");
qInbox.setString("userId", userid);

List noOfPagesList = qInbox.list();

qInbox.setFirstResult(PAGE_START);
qInbox.setMaxResults(PAGE_SIZE);

List listInbox = qInbox.list();

NO_OF_PAGES = ((noOfPagesList.size() % PAGE_SIZE) == 0) ? (noOfPagesList.size() / PAGE_SIZE) : ((noOfPagesList.size()/ PAGE_SIZE) + 1);

//PAGE_END = ((user.getInboxWorkItems().size() -1) <= (PAGE_START + PAGE_SIZE - 1)) ? (user.getInboxWorkItems().size() -1) : (PAGE_START + PAGE_SIZE - 1);

Object [] inboxWorkItemArray = listInbox.toArray();
%>

<%
String actionForm = "ViewForm=1&Approver=1";
if (isValidSALES(userrole)) actionForm = "EditForm=1";
%>

<%
String make_list = "";

for (int i = 0; i < inboxWorkItemArray.length; i++)
{
WorkItemTypeImpl po = (WorkItemTypeImpl) inboxWorkItemArray[i];

String Id = po.getMessageId();
String status = po.getMessageStatus();

List fieldlist = HibernateManager.decodeFieldNames (po.getFieldInternal());
HashMap nameValues = new HashMap();
for (int j = 0; j < fieldlist.size(); j++)
{
FieldType fT = (FieldType) fieldlist.get(j);
String fN = fT.getFieldName();
String fV = fT.getFieldValue();
nameValues.put (fN, fV);
}

make_list += "<TR align=right>";

make_list += "<TD> <a href=\"Work_Item.jsp?"+actionForm+"&Id=" + Id + "\">" + (String) nameValues.get("Order_No") + "</a> </TD>";

make_list += "<TD>" + (String) nameValues.get("Account_Name") + "</TD>";
make_list += "<TD>" + (String) nameValues.get("Contract_Value") + "</TD>";
make_list += "<TD>" + (String) nameValues.get("Currency_Type") + "</TD>";
make_list += "<TD>" + (String) nameValues.get("Sales_Person_Name") + "</TD>";

make_list += "<TD>" + status + "</TD>";

make_list += "</TR>";
}
%>

<%@ include file="templates/Inbox_template.jsp" %>

<%
tx.commit();
HibernateUtil.closeSession();
%>


This is my hibernate.properties file :


#########################################################################
# THIS FILE IS PART OF THE HyperJAXB SOURCE CODE. #
# USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS #
# GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE #
# IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. #
# #
# THE HyperJAXB SOURCE CODE IS (C) COPYRIGHT 2004 #
# by Aleksei Valikov, valikov@fzi.de #
#########################################################################



######################
### Query Language ###
######################

## define query language constants / function names

#hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'

## package imports

#hibernate.query.imports net.sf.hibernate.test



#################
### Platforms ###
#################

## JNDI Datasource

#hibernate.connection.datasource jdbc/test
#hibernate.connection.username db2
#hibernate.connection.password db2


## PostgreSQL

#hibernate.dialect net.sf.hibernate.dialect.PostgreSQLDialect
#hibernate.connection.driver_class org.postgresql.Driver
#hibernate.connection.url jdbc:postgresql:template1
#hibernate.connection.username pg
#hibernate.connection.password
#hibernate.query.substitutions yes 'Y', no 'N'


## DB2

#hibernate.dialect net.sf.hibernate.dialect.DB2Dialect
#hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver
#hibernate.connection.url jdbc:db2:test
#hibernate.connection.username db2
#hibernate.connection.password db2


## MySQL

hibernate.dialect org.hibernate.dialect.MySQLDialect
#hibernate.connection.driver_class org.gjt.mm.mysql.Driver
hibernate.connection.driver_class com.mysql.jdbc.Driver
hibernate.connection.url jdbc:mysql://:3306/wfs
hibernate.connection.username workuser
hibernate.connection.password redifforgwfs


## Oracle

#hibernate.dialect net.sf.hibernate.dialect.OracleDialect
#hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
#hibernate.connection.username ora
#hibernate.connection.password ora
#hibernate.connection.url jdbc:oracle:thin:@localhost:1521:test


## Sybase

#hibernate.dialect net.sf.hibernate.dialect.SybaseDialect
#hibernate.connection.driver_class com.sybase.jdbc2.jdbc.SybDriver
#hibernate.connection.username sa
#hibernate.connection.password sasasa
#hibernate.connection.rl jdbc:sybase:Tds:co3061835-a:5000/tempdb


## HypersonicSQL

#hibernate.dialect org.hibernate.dialect.HSQLDialect
#hibernate.connection.driver_class org.hsqldb.jdbcDriver
#hibernate.connection.username sa
#hibernate.connection.password
#hibernate.connection.url jdbc:hsqldb:database/tutorial
#hibernate.max_fetch_depth 0

## Mckoi SQL

#hibernate.dialect net.sf.hibernate.dialect.MckoiDialect
#hibernate.connection.driver_class com.mckoi.JDBCDriver
#hibernate.connection.url jdbc:mckoi:///
#hibernate.connection.url jdbc:mckoi:local://C:/mckoi1.00/db.conf
#hibernate.connection.username admin
#hibernate.connection.password nimda


## SAP DB

#hibernate.dialect net.sf.hibernate.dialect.SAPDBDialect
#hibernate.connection.driver_class com.sap.dbtech.jdbc.DriverSapDB
#hibernate.connection.url jdbc:sapdb://localhost/TST
#hibernate.connection.username TEST
#hibernate.connection.password TEST
#hibernate.query.substitutions yes 'Y', no 'N'


## MS SQL Server

#hibernate.dialect net.sf.hibernate.dialect.SybaseDialect
#hibernate.connection.username sa
#hibernate.connection.password

## JSQL Driver

#hibernate.connection.driver_class com.jnetdirect.jsql.JSQLDriver
#hibernate.connection.url jdbc:JSQLConnect://WL99LCX27

## JTURBO Driver

#hibernate.connection.driver_class com.newatlanta.jturbo.driver.Driver
#hibernate.connection.url jdbc:JTurbo://CO3061835-A:1433/master

## WebLogic Driver

#hibernate.connection.driver_class weblogic.jdbc.mssqlserver4.Driver
#hibernate.connection.url jdbc:weblogic:mssqlserver4:CO3061835-A:1433

## Microsoft Driver (not supported!)

#hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
#hibernate.connection.url jdbc:microsoft:sqlserver://CO3061835-A:1433;SelectMethod=cursor


## Interbase

#hibernate.dialect net.sf.hibernate.dialect.InterbaseDialect
#hibernate.connection.username sysdba
#hibernate.connection.password masterkey

## DO NOT specify hibernate.connection.sqlDialect

## InterClient

#hibernate.connection.driver_class interbase.interclient.Driver
#hibernate.connection.url jdbc:interbase://localhost:3060/C:/firebird/test.gdb

## Pure Java

#hibernate.connection.driver_class org.firebirdsql.jdbc.FBDriver
#hibernate.connection.url jdbc:firebirdsql:localhost/3050:/firebird/test.gdb


## Pointbase

#hibernate.dialect net.sf.hibernate.dialect.PointbaseDialect
#hibernate.connection.driver_class com.pointbase.jdbc.jdbcUniversalDriver
#hibernate.connection.url jdbc:pointbase:embedded:sample
#hibernate.connection.username PBPUBLIC
#hibernate.connection.password PBPUBLIC



#################################
### Hibernate Connection Pool ###
#################################

hibernate.connection.pool_size 1
###hibernate.statement_cache.size 25



###########################
### C3P0 Connection Pool###
###########################

#hibernate.c3p0.max_size 2
#hibernate.c3p0.min_size 2
#hibernate.c3p0.timeout 5000
#hibernate.c3p0.max_statements 100
#hibernate.c3p0.validate false



###################################
### Apache DBCP Connection Pool ###
###################################

## connection pool

#hibernate.dbcp.maxActive 100
#hibernate.dbcp.whenExhaustedAction 1
#hibernate.dbcp.maxWait 120000
#hibernate.dbcp.maxIdle 10

## prepared statement cache

#hibernate.dbcp.ps.maxActive 100
#hibernate.dbcp.ps.whenExhaustedAction 1
#hibernate.dbcp.ps.maxWait 120000
#hibernate.dbcp.ps.maxIdle 100

## optional query to validate pooled connections:

#hibernate.dbcp.validationQuery select 1 from dual
#hibernate.dbcp.testOnBorrow true
#hibernate.dbcp.testOnReturn false



##############################
### Proxool Connection Pool###
##############################

## Properties for external configuration of Proxool

#hibernate.proxool.pool_alias pool1

## Only need one of the following

#hibernate.proxool.existing_pool true
#hibernate.proxool.xml proxool.xml
#hibernate.proxool.properties proxool.properties

## Or, alternatively, all of these
## Standard configuration properties of Proxool

#hibernate.proxool.house-keeping-sleep-time 30000
#hibernate.proxool.house-keeping-test-sql
#hibernate.proxool.maximum-connection-count 4
#hibernate.proxool.maximum-connection-lifetime 4
#hibernate.proxool.simultaneous-build-throttle 2
#hibernate.proxool.maximum-active-time 500
#hibernate.proxool.minimum-connection-count 2
#hibernate.proxool.fatal-sql-exception
#hibernate.proxool.prototype-count
#hibernate.proxool.statistics
#hibernate.proxool.recently-started-threshold
#hibernate.proxool.overload-without-refusal-lifetime



#################################
### Plugin ConnectionProvider ###
#################################

## use a custom ConnectionProvider (if not set, Hibernate will choose a built-in ConnectionProvider using hueristics)

#hibernate.connection.provider_class net.sf.hibernate.connection.DriverManagerConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.C3P0ConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.DBCPConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.ProxoolConnectionProvider



#######################
### Transaction API ###
#######################

## the Transaction API abstracts application code from the underlying JTA or JDBC transactions

#hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
#hibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactory


## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
## default is java:comp/UserTransaction

#jta.UserTransaction jta/usertransaction
#jta.UserTransaction javax.transaction.UserTransaction
#jta.UserTransaction UserTransaction


## to use JTATransactionFactory with JCS caching, Hibernate must be able to obtain the JTA TransactionManager

#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.JBossTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.OrionTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.ResinTransactionManagerLookup



##############################
### Miscellaneous Settings ###
##############################

## print all generated SQL to the console

hibernate.show_sql true


## Automatically export schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly

#hibernate.hbm2ddl.auto create


## specify a JDBC isolation level

#hibernate.connection.isolation 4


## set the JDBC fetch size

#hibernate.jdbc.fetch_size 25


## set the maximum JDBC 2 batch size (a nonzero value enables batching)

#hibernate.jdbc.batch_size 0


## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)

#hibernate.jdbc.use_scrollable_resultset true


## use streams when writing binary types to / from JDBC

#hibernate.jdbc.use_streams_for_binary true


## specify a default schema for unqualified tablenames

#hibernate.default_schema test


## use a custom stylesheet for XML generation (if not specified, hibernate-default.xslt will be used)

#hibernate.xml.output_stylesheet C:/Hibernate/net/sf/hibernate/hibernate-default.xslt


## enable outerjoin fetching (specifying a Dialect will cause Hibernate to use sensible default)

#hibernate.use_outer_join false


## enable CGLIB reflection optimizer (enabled by default)

#hibernate.cglib.use_reflection_optimizer false



############
### JNDI ###
############

## specify a JNDI name for the SessionFactory

#hibernate.session_factory_name hibernate/session_factory


## Hibernate uses JNDI to bind a name to a SessionFactory and to look up the JTA UserTransaction;
## if hibernate.jndi.* are not specified, Hibernate will use the default InitialContext() which
## is the best approach in an application server

#file system
#hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactory
#hibernate.jndi.url file:/

#WebSphere
#hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
#hibernate.jndi.url iiop://localhost:900/




Once this error occurs it occurs for all jsp pages I visit.This exception occurs only for sometime and web application is fine again.

I am very much confused and facing this probelm at client side.Hibernate team please help me solve this problen.It is very urgent.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 8:55 am 
Regular
Regular

Joined: Tue Mar 07, 2006 11:18 am
Posts: 54
Location: Berlin
Hi,
I can remember having similar problems with the connection pool.
I did use the c3p0 - Pool as your did.
Actually I just updated the c3p0 jar to the latest version and the problem disappeared.

do you use the latest version?!

simon


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 2:53 am 
Newbie

Joined: Thu Mar 09, 2006 4:57 am
Posts: 2
Thanks.
I have used the new c3p0 connection pool now.
I am testing it.
Will let u know of the result.?


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