-->
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: bad sql is killing my sessionfactory
PostPosted: Sat Mar 24, 2007 2:30 pm 
Newbie

Joined: Thu Mar 08, 2007 1:58 pm
Posts: 6
Has anyone every experienced their session factory (I happen to use PostgreSQL) get hosed when a bad SQL throws an error. It seems if I have a typo or otherwise invalid SQL it throws an error and all my connections are placed in an error state.

If I restart the session factory, i.e. pool it fixes it. I swear I am ending my transactions properly but... here is my query code and HibernateUtil


public static List sqlQuery(String sql, ServiceCall call) throws Exception {
try {
List qrylist = null;
org.hibernate.Session session = HibernateUtil.getNewSession();
try {
Query query = session.createSQLQuery(sql);

qrylist = query.list();

session.clear();
} catch (Exception ex) {
Log.error(getDebug(sql, qualifications));
HibernateUtil.abort();
throw ex;
} finally {
session.close();
}
return qrylist;
} catch (Exception ex) {
throw ex;
}
}





public class HibernateUtil {

private static SessionFactory sessionFactory = null;
private static Configuration configuration = null;
private volatile static Object lock = new Object();

static {
buildSessionFactory();
}

private static synchronized void buildSessionFactory() {
try {
if (configuration == null) {
synchronized (lock) {
if (configuration == null) {
configuration = new Configuration().configure();
sessionFactory = configuration.buildSessionFactory();
}
}
}
} catch (Throwable ex) {
ex.printStackTrace(System.err);
Log.fatal(ex);
}
}

private static SessionFactory getSessionFactory() throws Exception {
if (sessionFactory == null) {
throw new NullPointerException();
} else {
return sessionFactory;
}
}

public static Session getNewSession() throws Exception {
try {
return getSessionFactory().openSession();
} catch (Exception ex) {
throw ex;
}
}

public static synchronized void abort() throws Exception {
try {
Log.error("abort!");
System.exit(1);
getSessionFactory().getCurrentSession().close();
sessionFactory = configuration.buildSessionFactory();
} catch (Exception ex) {
throw ex;
}
}


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.