openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Haim Schneider <HA...@il.ibm.com>
Subject Re: MySQLNonTransientConnectionException: Can't call rollback when autocommit=true
Date Thu, 13 Mar 2014 15:33:39 GMT
I'm using Spring + OpenJPA + WebSphere Liberty 8.5. The same code works OK 
with a DB2 datasource, but fails with MySQL. 

The persistemce.xml is the following:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
        xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
        <persistence-unit name="MAMServicePU" 
transaction-type="RESOURCE_LOCAL">
 
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
                <jta-data-source>jdbc/mydb_mysql</jta-data-source>
                <class>com.ibm.Test1</class>
                <class>com.ibm.Test2</class>

                <properties>
                        <property name="openjpa.jdbc.DBDictionary" 
value="mysql" />
                        <property name="openjpa.jdbc.Schema" value="test" 
/>
                        <property name="openjpa.jdbc.SynchronizeMappings" 
value="buildSchema(ForeignKeys=true,Indexes=false)" />
                        <property name="openjpa.Log" 
value="DefaultLevel=TRACE, SQL=TRACE"/>
                </properties>
        </persistence-unit>
</persistence>

 The openJPA trace does not show anything unusual.

The interesting part is that I checked the SchemaTool.java source code and 
found that it always calls roolback() before executing DDL. The comment in 
the SchemaTool code is the following:

                        // some connections require that rollback be
                        // called on the connection before any DDL 
statements
                        // can be run on it, even when autocommit is on.
                        // This is sometimes because the connection does 
not
                        // allow DDL statements when there are multiple
                        // commands issued on the connection, and the
                        // connection pool may have issued some validation 
SQL.

So from what I see in the code, rollback is always called before executing 
the DDL statements, and autocommit is explicitly set to true, which leads 
to the MySQL exception. 

Thanks,
Haim 





From:   Kevin Sutter <kwsutter@gmail.com>
To:     users@openjpa.apache.org, 
Date:   13/03/2014 05:00 PM
Subject:        Re: MySQLNonTransientConnectionException: Can't call 
rollback when autocommit=true



You seem to have several frameworks involved here...  Spring and JPA
(OpenJPA).  You also seem to be using WebSphere?  Is this the Liberty
profile or the full platform WebSphere?  What version?

Can you post your persistence.xml file?

Do you have any other errors or warnings in your logs prior to this
exception?  As Albert was asking, I'm wondering if there is just some
disconnect between your MySQL database and the JPA access...

Thanks, Kevin


On Thu, Mar 13, 2014 at 9:23 AM, Albert Lee <allee8285@gmail.com> wrote:

> Wondering what is the cause of the rollback from the SchemaTool, i.e.
>
> org.apache.openjpa.lib.jdbc.
>
> 
ConfiguringConnectionDecorator$ConfiguringConnection.rollback(ConfiguringConnectionDecorator.java:132)
>         at
> 
org.apache.openjpa.jdbc.schema.SchemaTool.executeSQL(SchemaTool.java:1219)
>
> and what data source type was used?
>
>
>
> On Thu, Mar 13, 2014 at 7:59 AM, Haim Schneider <HAIMS@il.ibm.com> 
wrote:
>
> > Automatic table generation fails with MySQL. I get the exception:
> >
> > MySQLNonTransientConnectionException: Can't call rollback when
> > autocommit=true
> >
> > This exception causes the connection to be closed, and the automatic
> table
> > generation fails.
> >
> > The exception is thrown by the SchemaTool.executeSQL method. I checked
> the
> > source code and found that the method calls rollback prior to 
executing
> > the SQL statement. The problem is that the method also set autocommit 
to
> > true before calling rollback, and this leads to the
> > MySQLNonTransientConnectionException that causes the connection to be
> > closed.
> >
> > Is there any workaround?
> >
> > The complete exception is:
> >
> > com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
> > Can't call rollback when autocommit=true
> >         at 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> > Method)
> >         at
> >
> >
> 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
> >         at
> >
> >
> 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
> >         at
> java.lang.reflect.Constructor.newInstance(Constructor.java:526)
> >         at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
> >         at com.mysql.jdbc.Util.getInstance(Util.java:386)
> >         at 
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
> >         at 
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
> >         at 
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
> >         at 
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
> >         at
> > com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:5065)
> >         at
> >
> >
> 
com.mysql.jdbc.jdbc2.optional.ConnectionWrapper.rollback(ConnectionWrapper.java:794)
> >         at
> >
> >
> 
com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.rollback(WSJdbcConnection.java:2593)
> >         at
> >
> >
> 
org.apache.openjpa.lib.jdbc.DelegatingConnection.rollback(DelegatingConnection.java:179)
> >         at
> >
> >
> 
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.rollback(LoggingConnectionDecorator.java:356)
> >         at
> >
> >
> 
org.apache.openjpa.lib.jdbc.DelegatingConnection.rollback(DelegatingConnection.java:179)
> >         at
> >
> >
> 
org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.rollback(ConfiguringConnectionDecorator.java:132)
> >         at
> >
> 
org.apache.openjpa.jdbc.schema.SchemaTool.executeSQL(SchemaTool.java:1219)
> >         at
> >
> 
org.apache.openjpa.jdbc.schema.SchemaTool.createTable(SchemaTool.java:975)
> >         at
> > org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:551)
> >         at
> > org.apache.openjpa.jdbc.schema.SchemaTool.add(SchemaTool.java:366)
> >         at
> > org.apache.openjpa.jdbc.schema.SchemaTool.run(SchemaTool.java:343)
> >         at
> > org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:505)
> >         at
> > org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:455)
> >         at
> >
> >
> 
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:160)
> >         at
> >
> >
> 
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:164)
> >         at
> >
> >
> 
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:122)
> >         at
> >
> >
> 
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:209)
> >         at
> >
> >
> 
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
> >         at
> >
> >
> 
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
> >         at
> >
> >
> 
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
> >         at
> >
> >
> 
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
> >         at
> >
> >
> 
org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:445)
> >         at
> >
> >
> 
org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:366)
> >         at
> >
> >
> 
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
> >         at
> >
> >
> 
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:336)
> >         at
> >
> >
> 
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
> >         at
> >
> >
> 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> >         at
> >
> >
> 
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622)
> >         at
> >
> >
> 
com.ibm.mbaas.mam.dao.MAMClientDAO$$EnhancerByCGLIB$$e32fb58f.getAllMetadata(<generated>)
> >         at
> >
> >
> 
com.ibm.mbaas.mam.controllers.ClientMetadataController.getClients(ClientMetadataController.java:173)
> >         at
> >
> >
> 
com.ibm.mbaas.mam.controllers.ClientMetadataController.getAllClientsMetadata(ClientMetadataController.java:105)
> >         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >         at
> >
> >
> 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> >         at
> >
> >
> 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> >         at java.lang.reflect.Method.invoke(Method.java:606)
> >         at
> >
> >
> 
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
> >         at
> >
> >
> 
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
> >         at
> >
> >
> 
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
> >         at
> >
> >
> 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
> >         at
> >
> >
> 
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
> >         at
> >
> >
> 
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
> >         at
> >
> >
> 
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
> >         at
> >
> >
> 
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
> >         at
> >
> >
> 
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
> >         at
> >
> >
> 
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
> >         at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:575)
> >         at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1240)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:760)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:443)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:127)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:88)
> >         at
> >
> >
> 
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
> >         at
> >
> >
> 
org.cloudfoundry.identity.uaa.security.web.SecurityFilterChainPostProcessor$UaaLoggingFilter.doFilter(SecurityFilterChainPostProcessor.java:195)
> >         at
> >
> >
> 
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
> >         at
> >
> >
> 
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
> >         at
> >
> >
> 
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
> >         at
> >
> >
> 
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
> >         at
> >
> >
> 
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:194)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:85)
> >         at
> >
> >
> 
com.ibm.ws.icap.security.uaa.filter.OverrideServerPortFilter.doFilter(OverrideServerPortFilter.java:48)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:194)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:85)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:949)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1029)
> >         at
> > com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:4499)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.handleRequest(DynamicVirtualHost.java:282)
> >         at
> > 
com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:954)
> >         at
> >
> >
> 
com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:252)
> >         at
> >
> >
> 
com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:584)
> >         at
> > com.ibm.ws.threading.internal.Worker.executeWork(Worker.java:439)
> >         at com.ibm.ws.threading.internal.Worker.run(Worker.java:421)
> >         at java.lang.Thread.run(Thread.java:724)
> >
> > Thanks,
> > Haim Schneider
>
>
>
>
> --
> Albert Lee.
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message