We developed application using Hibernate 3/Sybase 15/Weblogic AS. It works just fine for smaller result-sets. i.e. for less data retrieval. <br/>
But for larger results, it gives following exception and strangely it doesn't happen consistently. <br/>
Quote:
> [DEBUG] [SQL:401] - SELECT DISTINCT CLUSTER_ID, CLUSTER_NAME, CUSTOMER_ID, CUSTOMER_NAME FROM _ENTITIES (index IDX_01) WHERE CLUSTER_ID=10532 ORDER BY CUSTOMER_ID
[ERROR] [JDBCExceptionReporter:78] - **JZ006: Caught IOException: java.io.IOException: JZ0PA: The query has been cancelled and the response discarded. The cancel was probably issued by another statement on the connection.**
[ERROR] [FacadeBean:1075] - [E2E00097] - could not execute query
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2216)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at be..mobile..be.dao.EntityDAO.findClusterByClusterID(EntityDAO.java:263)
at be..mobile..be.services..FacadeBean.getDiscountByGroupID(FacadeBean.java:869)
at be..mobile..be.services..FacadeBean_f4808s_EOImpl.__WL_invoke(Unknown Source)
at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:40)
at be..mobile..be.services..FacadeBean_f4808s_EOImpl.getDiscountByGroupID(Unknown Source)
at be..mobile..be.services..FacadeBean_f4808s_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:174)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:345)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at be..mobile..be.services..FacadeBean_f4808s_EOImpl_1036_WLStub.getDiscountByGroupID(Unknown Source)
at be..mobile..fe.util.AGLDScreensDelegate.getDiscountByGroupID(AGLDScreensDelegate.java:209)
at be..mobile..fe.struts.action.AGLDSearchScreenAction.select(AGLDSearchScreenAction.java:281)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at be..mobile..fe.util.AuthenticationFilter.doFilter(AuthenticationFilter.java:64)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3730)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3696)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2273)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1490)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused by: java.sql.SQLException: JZ006: Caught IOException: java.io.IOException: JZ0PA: The query has been cancelled and the response discarded. The cancel was probably issued by another statement on the connection.
at com.sybase.jdbc2.jdbc.ErrorMessage.raiseError(ErrorMessage.java:493)
at com.sybase.jdbc2.jdbc.ErrorMessage.raiseErrorCheckDead(ErrorMessage.java:729)
at com.sybase.jdbc2.tds.Tds.handleIOE(Tds.java:3107)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1876)
at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:204)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:187)
at com.sybase.jdbc2.jdbc.SybStatement.queryLoop(SybStatement.java:1537)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:1522)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:72)
at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:135)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2213)
... 51 more
We checked the exception handling and Hibernate session handling. It looks real perfect.
And the issue pops up suddenly in recent UAT deployment (application is quite stable in PROD for last few years).<br/>
I have placed DAO connection handling source snippet here, note that once complete the DAO operations, 'closeSession' method will be invoked in service method's finally block <br/>
Code:
public class HibernateSessionFactory {
private static final ThreadLocal threadLocal = new ThreadLocal();
private static final ThreadLocal threadInterceptor = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
if (getInterceptor() != null) {
session = (sessionFactory != null) ? sessionFactory.openSession(getInterceptor())
: null;
} else {
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
}
threadLocal.set(session);
}
return session;
}
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
public static void commitTransaction() {
Session session = (Session) threadLocal.get();
if (session != null) {
session.flush();
}
Transaction tx = (Transaction) threadTransaction.get();
if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
tx.commit();
}
threadTransaction.set(null);
}
public static void rollbackTransaction() {
Transaction tx = (Transaction) threadTransaction.get();
if (tx != null && !tx.wasCommitted() && !tx.wasRolledBack() && tx.isActive()) {
tx.rollback();
}
threadTransaction.set(null);
}
}
<br/><br/>
I have been searching in Forums for this issue, but left with no option. Does anyone know why this exception occurs inconsistently? and the root cause of this issue?
Any help would be greatly appreciated. Thanks.