title: Setting Query timeout throws ORA-12592: TNS:bad packet
body: <p>Let me get it straight first - I do not know anything about EJBs.</p>
  
  <p>Coming back to the question, we have a function in oracle which we call from our application. </p>
  
  <p>Below are the steps to make the call:</p>
  
  <pre><code>- get the EnitityManager
  - create a named query.
  - set parameters on the query object
  - query.executeUpdate()
  </code></pre>
  
  <p>I am trying to set a timeout on the query. I have tried many possibilities:</p>
  
  <pre><code>- hibernateQuery.setTimeout(value);
  - jpaQuery.setHint("javax.persistence.query.timeout", value);
  - &lt;sql-query .. timeout="30"  .. on the hbm file.
  - javax.transaction.UserTransaction.setTransactionTimeout(timeout);
  </code></pre>
  
  <p>All of them did not timeout but ran for that stipulated time, the query was suppose to run and finally throws ORA-12592: TNS:bad packet.</p>
  
  <p>I searched for ORA-12592, and most of the searches indicate a connection issue on the firewall/OS/network. What I fail to understand is why does it not throw ORA-12592, if I do not set a timeout.</p>
  
  <p>More importantly, how do I set a timeout? Do you think it is a problem with the oracle driver?</p>
  
  <h2>More details about the configuration</h2>
  
  <pre><code>Persistence Provider Class: org.hibernate.ejb.HibernatePersistence
  Driver Class: oracle.jdbc.xa.client.OracleXADataSource
  Hibernate 4 [with JPA 2]
  EJB 3
  </code></pre>
  
  <p>Edited: adding the stack trace:</p>
  
  <pre><code>javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
  at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:273)
  at com.abc.star.jpa.service.BasePersistenceService.getResultList(BasePersistenceService.java:118)
  at com.abc.star.jpa.service.StarPersistenceService$$EnhancerByGuice$$e3e37c96.CGLIB$getResultList$8(&lt;generated&gt;)
  at com.abc.star.jpa.service.StarPersistenceService$$EnhancerByGuice$$e3e37c96$$FastClassByGuice$$f5d274d4.invoke(&lt;generated&gt;)
  at com.google.inject.internal.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
  at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:64)
  at com.abc.star.common.TransactionalHandler.invoke(TransactionalHandler.java:29)
  at com.google.inject.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:64)
  at com.google.inject.InterceptorStackCallback.intercept(InterceptorStackCallback.java:44)
  at com.abc.star.jpa.service.StarPersistenceService$$EnhancerByGuice$$e3e37c96.getResultList(&lt;generated&gt;)
  at com.abc.star.jpa.service.StarPersistenceService.getClearance(StarPersistenceService.java:25)
  at com.abc.star.jpa.service.StarPersistenceService$$EnhancerByGuice$$e3e37c96.CGLIB$getClearance$0(&lt;generated&gt;)
  at com.abc.star.jpa.service.StarPersistenceService$$EnhancerByGuice$$e3e37c96$$FastClassByGuice$$f5d274d4.invoke(&lt;generated&gt;)
  at com.google.inject.internal.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
  at com.google.inject.ProxyFactory$1.intercept(ProxyFactory.java:53)
  at com.abc.star.jpa.service.StarPersistenceService$$EnhancerByGuice$$e3e37c96.getClearance(&lt;generated&gt;)
  at com.abc.star.service.StarInfo.getCompositeStatus(StarInfo.java:69)
  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 com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:167)
  at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:70)
  at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:279)
  at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
  at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:86)
  at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:136)
  at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:74)
  at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1350)
  at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1282)
  at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1232)
  at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1222)
  at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:419)
  at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
  at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:216)
  at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:141)
  at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:93)
  at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:63)
  at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
  at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:59)
  at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:134)
  at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:59)
  at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:122)
  at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:110)
  at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
  at com.abc.star.common.web.PersistenceInterceptor.doFilter(PersistenceInterceptor.java:79)
  at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
  at com.abc.star.common.web.GlobalsInterceptor.doFilter(GlobalsInterceptor.java:53)
  at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
  at com.abc.mnm.filter.MnmAuthFilter.doFilter(MnmAuthFilter.java:112)
  at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
  at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
  at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
  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:2277)
  at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
  at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
  at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
  at weblogic.work.ExecuteThread.run(ExecuteThread.java:176)
  
  Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
  at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
  at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
  at org.hibernate.loader.Loader.doList(Loader.java:2525)
  at org.hibernate.loader.Loader.doList(Loader.java:2508)
  at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2338)
  at org.hibernate.loader.Loader.list(Loader.java:2333)
  at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338)
  at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1827)
  at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:231)
  at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:157)
  at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:264)
  ... 61 more
  
  Caused by: java.sql.SQLException: ORA-12592: TNS:bad packet
  
  at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
  at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
  at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
  at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
  at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
  at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
  at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193)
  at oracle.jdbc.driver.T4CStatement.fetch(T4CStatement.java:1072)
  at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:359)
  at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:263)
  at weblogic.jdbc.wrapper.ResultSet_oracle_jdbc_driver_OracleResultSetImpl.next(Unknown Source)
  at org.hibernate.loader.Loader.processResultSet(Loader.java:939)
  at org.hibernate.loader.Loader.doQuery(Loader.java:910)
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341)
  at org.hibernate.loader.Loader.doList(Loader.java:2522)
  </code></pre>