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/>
> [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.handledN onSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert( SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.conver t(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:221 6)
at org.hibernate.loader.Loader.listIgnoreQueryCache(L oader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.custom.CustomLoader.list(Cust omLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(Ses sionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(Abstra ctSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl. java:152)
at be..mobile..be.dao.EntityDAO.findClusterByClusterI D(EntityDAO.java:263)
at be..mobile..be.services..FacadeBean.getDiscountByG roupID(FacadeBean.java:869)
at be..mobile..be.services..FacadeBean_f4808s_EOImpl. __WL_invoke(Unknown Source)
at weblogic.ejb.container.internal.SessionRemoteMetho dInvoker.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(Se rverRequest.java:174)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(C lusterableRemoteRef.java:345)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(C lusterableRemoteRef.java:259)
at be..mobile..be.services..FacadeBean_f4808s_EOImpl_ 1036_WLStub.getDiscountByGroupID(Unknown Source)
at be..mobile..fe.util.AGLDScreensDelegate.getDiscoun tByGroupID(AGLDScreensDelegate.java:209)
at be..mobile..fe.struts.action.AGLDSearchScreenActio n.select(AGLDSearchScreenAction.java:281)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchM ethod(DispatchAction.java:269)
at org.apache.struts.actions.DispatchAction.execute(D ispatchAction.java:170)
at org.apache.struts.chain.commands.servlet.ExecuteAc tion.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAc tion.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase .execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.exe cute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(Ch ainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor .process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(Actio nServlet.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$Servl etServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invok eServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute( ServletStubImpl.java:301)
at weblogic.servlet.internal.TailFilter.doFilter(Tail Filter.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$Ser vletInvocationAction.wrapRun(WebAppServletContext. java:3730)
at weblogic.servlet.internal.WebAppServletContext$Ser vletInvocationAction.run(WebAppServletContext.java :3696)
at weblogic.security.acl.internal.AuthenticatedSubjec t.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Se curityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.sec uredExecute(WebAppServletContext.java:2273)
at weblogic.servlet.internal.WebAppServletContext.exe cute(WebAppServletContext.java:2179)
at weblogic.servlet.internal.ServletRequestImpl.run(S ervletRequestImpl.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(Erro rMessage.java:493)
at com.sybase.jdbc2.jdbc.ErrorMessage.raiseErrorCheck Dead(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(Resu ltGetter.java:69)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybS tatement.java:204)
at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybS tatement.java:187)
at com.sybase.jdbc2.jdbc.SybStatement.queryLoop(SybSt atement.java:1537)
at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(Sy bStatement.java:1522)
at com.sybase.jdbc2.jdbc.SybPreparedStatement.execute Query(SybPreparedStatement.java:72)
at weblogic.jdbc.wrapper.PreparedStatement.executeQue ry(PreparedStatement.java:135)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(Ab stractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.ja va:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:67 4)
at org.hibernate.loader.Loader.doQueryAndInitializeNo nLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:221 3)
... 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);
    }

}

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.