On Thu, 07 May 2015 10:07:44 +0300 ????????? ???????? <ooo_saturn7@xxxxxxx> wrote: > > I have postgresql 9.4 and glassfish 4.1. Besides I use MyBatis inside EJB. Now I try to make select from table and this is what I get: > javax.resource.spi.LocalTransactionException:Cannot commit when autoCommit is enabled. > at com.sun.gjc.spi.LocalTransactionImpl.commit(LocalTransactionImpl.java:112) > at com.sun.enterprise.resource.ConnectorXAResource.commit(ConnectorXAResource.java:124) > at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:518) > at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:854) > at com.sun.ejb.containers.EJBContainerTransactionManager.completeNewTx(EJBContainerTransactionManager.java:719) > at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:503) > at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566) > at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074) > at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044) > at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212) > at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79) > at com.sun.proxy.$Proxy312.getLsist(UnknownSource) > at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:483) > at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143) > at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173) > at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528) > at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199) > at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549) > at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425) > at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930) > at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213) > at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694) > at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496) > at com.sun.corba.ee.impl.transport.ConnectionImpl$1.dispatch(ConnectionImpl.java:195) > at com.sun.corba.ee.impl.transport.ConnectionImpl.read(ConnectionImpl.java:328) > at com.sun.corba.ee.impl.transport.ReaderThreadImpl.doWork(ReaderThreadImpl.java:112) > at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497) > at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)Causedby: org.postgresql.util.PSQLException:Cannot commit when autoCommit is enabled. > at org.postgresql.jdbc2.AbstractJdbc2Connection.commit(AbstractJdbc2Connection.java:811) > at com.sun.gjc.spi.LocalTransactionImpl.commit(LocalTransactionImpl.java:106)...30 more > I even tried the following code: > SqlSession session =ConnectionFactory.getSession().openSession(false);//AUTOCOMMITList list=null; > try{ > session.getConnection().setAutoCommit(false); > TempMapper mapper =(TempMapper)session.getMapper(TempMapper.class); > list=mapper.readAll(); > }catch(SQLException ex){Logger.getLogger(TempBean.class.getName()).log(Level.SEVERE,null, ex);} > finally{ > session.close();} > However the result is the same. When I used gf+mysql+mybatis I changed relaxautocommit but for postgresql driver there is no such attribute. How to solve it? Best guess, based on experience, is that somehow you're disabling autocommit on a different connection from the one where you're doing the commit. I've seen this sort of thing happen with connection poolers where the developers don't fully understand how the connection pool works. You could confirm this by turning on full query logging in Postgres and see which connection does what. If it turns out to be the case, then you'll have sort out how your code is getting confused. If it's not the case, then I don't have any other ideas, but the full query logging will also tell you whether the command to disable autocommit really is being issued to PostgreSQL as well ... so still might be useful. -- Bill Moran -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general