My web application does not get page cannot be displayed or something even if this error occurs. It just proceeds fine. Where ever hibernate does a "select" I get this error.
Here are the details of how my code works:
public List fldrRow(long fldrNum)
{
List result = null;
try
{
Session session = HibernateSessionFactory.currentSession();
if(session!=null)
{
System.out.println("The folderNumber from attribute is "+fldrNum);
result = session.createQuery("from FolderGS as fg1 where fg1.folderNumber = "+fldrNum).list();
}
}
catch (HibernateException e)
{
throw new RuntimeException(e.getMessage());
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
HibernateSessionFactory.closeSession();
}
if(result==null)
return null;
else
return result;
}
This is from HibernateSessionFactory.java
package ne.dds.caseControl.efi.hibernate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
/**
* Basic Hibernate helper class, handles SessionFactory, Session and Transaction.
* <p>
* Uses a static initializer for the initial SessionFactory creation
* and holds Session and Transactions in thread local variables.
*
* This code has been re-written based on the original HibernateUtil.java, which was created by
christain@hibernate.org
*
*/
public class HibernateSessionFactory {
private static Log log = LogFactory.getLog(HibernateSessionFactory.class);
private static Configuration configuration;
private static SessionFactory sessionFactory;
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
// Create the initial SessionFactory from [edcs.hibernate.cfg.xml] configuration file
static {
try {
configuration = new Configuration();
sessionFactory = configuration.configure(CONFIG_FILE_LOCATION).buildSessionFactory();
} catch (Throwable ex) {
// We have to catch Throwable, otherwise we will miss
// NoClassDefFoundError and other subclasses of Error
log.error("Building SessionFactory failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}
/**
* Returns the SessionFactory used for this static class.
*
* @return SessionFactory
*/
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* Retrieves the current Session local to the thread.
* <p/>
* If no Session is open, opens a new Session for the running thread.
*
* @return Session
*/
public static Session getSession() throws HibernateException {
try {
Session s = (Session) threadSession.get();
if (s == null) {
//log.info("Opening new Session for this thread.");
s = getSessionFactory().openSession();
threadSession.set(s);
}
return s;
}catch(HibernateException ex){
throw ex;
}
}
public static Session getNewSession() throws HibernateException {
Session s = null;
s = getSessionFactory().openSession();
return s;
}
/**
* Retrieves the current Session local to the thread.
* <p/>
* If no Session is open, opens a new Session for the running thread.
*
* @return Session
*/
public static Session currentSession() throws HibernateException {
try {
Session s = (Session) threadSession.get();
if (s == null) {
//log.info("Opening new Session for this thread.");
s = getSessionFactory().openSession();
threadSession.set(s);
}
return s;
}catch(HibernateException ex){
throw ex;
}
}
/**
* Closes the Session local to the thread.
*/
public static void closeSession() throws HibernateException {
try {
Session s = (Session) threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen()) {
//log.info("Closing Session for this thread.");
s.close();
s = null;
}
}catch(HibernateException ex){
throw ex;
}
}
/**
* Closes the Session local to the thread.
*/
public static void close() throws HibernateException {
try {
Session s = (Session) threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen()) {
//log.info("Closing Session for this thread.");
s.close();
s = null;
}
}catch(HibernateException ex){
throw ex;
}
}
/**
* Start a new database transaction.
*/
public static void beginTransaction() throws HibernateException {
try {
Transaction tx = (Transaction) threadTransaction.get();
if (tx == null) {
//log.info("Starting new database transaction in this thread.");
tx = getSession().beginTransaction();
threadTransaction.set(tx);
}
} catch (HibernateException ex){
throw ex;
}
}
/**
* Commit the database transaction.
*/
public static void commitTransaction() throws HibernateException {
Transaction tx = (Transaction) threadTransaction.get();
try {
if ( tx != null && !tx.wasCommitted()
&& !tx.wasRolledBack() ) {
//log.info("Committing database transaction in this thread.");
tx.commit();
}
threadTransaction.set(null);
} catch (HibernateException ex) {
rollbackTransaction();
throw ex;
}
}
/**
* Rollback the database transaction.
*/
public static void rollbackTransaction() throws HibernateException {
Transaction tx = (Transaction) threadTransaction.get();
try {
threadTransaction.set(null);
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
//log.info("Tyring to rollback database transaction in this thread.");
tx.rollback();
}
} catch (HibernateException ex) {
throw ex;
} finally {
closeSession();
}
}
}
This is my hibernate.cfg.xml file
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"C:\neb\hibernate-configuration-3.0.dtd">
<!-- D:\Mystery\TestSample\JavaSource\ -->
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:jtds:sqlserver://10.211.179.200:1433/backupcasemsbesql;TDS=4.2</property>
<!-- jdbc:jtds:sqlserver://172.31.68.130:1433/Northwind;TDS=7.0 -->
<!-- jdbc:jtds:sqlserver://172.31.68.220:1433/backupcasemsbesql;TDS=7.0 -->
<property name="hibernate.connection.username">jimw</property>
<property name="hibernate.connection.password"></property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.cache.use_minimal_puts">false</property>
<!-- EFI Tables -->
<mapping resource="ne/dds/caseControl/efi/mapping/Folder.hbm.xml"/>
</session-factory>
</hibernate-configuration>