We are using hibernate configured to use weblogic connection pool. Whenever database is restarted without restarting weblogic, we get the following exceptions in our application.
java.lang.Throwable: org.hibernate.TransactionException: Transaction not successfully started
at com.verisign.vps.common.dao.hibernateimpl._RootDAO.closeSession(_RootDAO.java:390)
at com.verisign.vps.common.dao.hibernateimpl._RootDAO.closeSession(_RootDAO.java:355)
at com.verisign.vps.common.dao.hibernateimpl._RootDAO.closeLiveSession(_RootDAO.java:335)
at com.verisign.vps.common.dao.hibernateimpl._RootDAO.closeCurrentThreadSessions(_RootDAO.java:400)
at com.verisign.vps.webapps.pandora.action.PandoraBaseAction.execute(PandoraBaseAction.java:91)
If the application server is restarted or left for 24 hours, the problem seem to disappear. We configured weblogic such that if there is a connection problem, it will refresh its connection pool. Not sure what is wrong, please advise. Is there anyway to prevent this error without restarting the application server?
[b]Hibernate version:3.1.2[/b]
[b]Mapping documents:
hibernate.cfg.xml
--------------------
<hibernate-configuration>
<session-factory>
<!-- following configuration parameters will have their values customized at deployment-->
<property name="show_sql">false</property>
<property name="connection.datasource">XXXX</property>
<!-- end of customized configuration parameters -->
<property name="default_schema">PAY</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="jdbc.batch_versioned_data">true</property>
<property name="jdbc.use_streams_for_binary">true</property>
<property name="order_updates">true</property>
<property name="max_fetch_depth">1</property>
<property name="default_batch_fetch_size">8</property>
<property name="cache.use_second_level_cache">false</property>
weblogic config.xml
------------------------
<JDBCDataSource JNDIName="XXXX" Name="Live JDBC Data Source"
PoolName="JDBC MultiPool-1" Targets="VRSN_cluster"/>
<JDBCConnectionPool CapacityIncrement="1"
DriverName="oracle.jdbc.OracleDriver" InitialCapacity="1"
MaxCapacity="5" Name="JDBC Connection Pool-1"
Password="XXXX" Properties="user=XXX"
Targets="VRSN_cluster"
TestConnectionsOnRelease="true" TestConnectionsOnReserve="true"
TestTableName="DUAL" URL="jdbc:oracle:thin:@XX.XX.XX.XX:1521:PQ"/>
<JDBCConnectionPool CapacityIncrement="1"
DriverName="oracle.jdbc.OracleDriver" InitialCapacity="1"
MaxCapacity="5" Name="JDBC Connection Pool-2"
Password="XXXX" Properties="user=XXX"
Targets="VRSN_cluster"
TestConnectionsOnRelease="true" TestConnectionsOnReserve="true"
TestTableName="DUAL" URL="jdbc:oracle:thin:@XX.XX.XX.XX:1521:EPQ"/>
<JDBCMultiPool HighAvail="true" LoadBalance="false"
Name="JDBC MultiPool-1"
PoolList="JDBC Connection Pool-1,JDBC Connection Pool-2" Targets="VRSN_cluster"/>
[/b]
[b]Code between sessionFactory.openSession() and session.close():
public class HibernateUtil {
private static Configuration configuration;
private static SessionFactory sessionFactory;
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
private static final ThreadLocal threadInterceptor = new ThreadLocal();
// Create the initial SessionFactory from the default configuration files
static {
try {
configuration = new Configuration();
sessionFactory = configuration.configure().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);
}
}
public static Session getSession()
throws VpsException {
Session s = (Session) threadSession.get();
try {
if (s == null) {
log.debug("Opening new Session for this thread.");
if (getInterceptor() != null) {
log.debug("Using interceptor: " + getInterceptor().getClass());
s = getSessionFactory().openSession(getInterceptor());
} else {
s = getSessionFactory().openSession();
}
threadSession.set(s);
}
} catch (HibernateException ex) {
throw new VpsException(ex);
}
return s;
}
/**
* Closes the Session local to the thread.
*/
public static void closeSession()
throws VpsException {
try {
Session s = (Session) threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen()) {
log.debug("Closing Session of this thread.");
s.close();
}
} catch (HibernateException ex) {
throw new VpsException(ex);
}
}
/**
* Start a new database transaction.
*/
public static void beginTransaction()
throws VpsException {
Transaction tx = (Transaction) threadTransaction.get();
try {
if (tx == null) {
log.debug("Starting new database transaction in this thread.");
tx = getSession().beginTransaction();
threadTransaction.set(tx);
}
} catch (HibernateException ex) {
throw new VpsException(ex);
}
}
/**
* Commit the database transaction.
*/
public static void commitTransaction()
throws VpsException {
Transaction tx = (Transaction) threadTransaction.get();
try {
if (tx != null && !tx.wasCommitted()
&& !tx.wasRolledBack()) {
log.debug("Committing database transaction of this thread.");
tx.commit();
}
threadTransaction.set(null);
} catch (HibernateException ex) {
rollbackTransaction();
throw new VpsException(ex);
}
}
/**
* Commit the database transaction.
*/
public static void rollbackTransaction()
throws VpsException {
Transaction tx = (Transaction) threadTransaction.get();
try {
threadTransaction.set(null);
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack()) {
log.debug("Tyring to rollback database transaction of this thread.");
tx.rollback();
}
} catch (HibernateException ex) {
throw new VpsException(ex);
} finally {
closeSession();
}
}
/**
* Disconnect and return Session from current Thread.
*
* @return Session the disconnected Session
*/
public static Session disconnectSession()
throws VpsException {
Session session = getSession();
try {
threadSession.set(null);
if (session.isConnected() && session.isOpen())
session.disconnect();
} catch (HibernateException ex) {
throw new VpsException(ex);
}
return session;
}
/**
* Register a Hibernate interceptor with the current thread.
* <p/>
* Every Session opened is opened with this interceptor after
* registration. Has no effect if the current Session of the
* thread is already open, effective on next close()/getSession().
*/
public static void registerInterceptor(Interceptor interceptor) {
threadInterceptor.set(interceptor);
}
private static Interceptor getInterceptor() {
Interceptor interceptor =
(Interceptor) threadInterceptor.get();
return interceptor;
}
[/b]
[b]Name and version of the database you are using:Oracle 10g[/b]
|