java.sql.SQLException: You cannot commit during a managed transaction

六眼飞鱼酱① 提交于 2019-12-11 03:36:41

问题


In jboss 7, I have below config

<datasource jndi-name="java:jboss/env/esilicon/vms/OracleDBPoolNonXA" pool-name="ExampleDS">
    <connection-url>jdbc:oracle:thin:@erptstdb.sc.kaka.com:14100:ERPTST</connection-url>
    <driver>XAOracleJDBCDriver</driver>
    <pool>
        <min-pool-size>10</min-pool-size>
        <max-pool-size>20</max-pool-size>
        <prefill>true</prefill>
    </pool>
    <security>
        <user-name>apps</user-name>
        <password>apps</password>
    </security>
</datasource>
<drivers>
    <driver name="XAOracleJDBCDriver" module="oracle.jdbc">
        <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    </driver>
</drivers>

In orther class, I've method to get the connection for datasource

public static Connection getNonXAConnection() {
    try {
        InitialContext context = new InitialContext();
        DataSource dataSource = (DataSource)context.lookup(JNDILookup.PURE_CONNECTION_JNDI);
        return dataSource.getConnection();
    } catch (Exception e) {
        e.printStackTrace();
        logger.fatal(e.getMessage(), e.getCause());
    }
    return null;
}

The error occur when I commit this connection

java.sql.SQLException: You cannot commit during a managed transaction!
 at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:981)
 at org.jboss.jca.adapters.jdbc.WrappedConnection.commit(WrappedConnection.java:757)

I just like to get connection and execute some stored procedure, and finnaly commit this connection. Please help me


回答1:


Use an anotation like this:

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class SchedulerBean {

I was facing same problem with Quartz and was able to solve this way.




回答2:


I had this error when specifying an incorrect remoting address in the standalone.xml file. The value should normally be:

<socket-binding name="remoting" port="4447"/>

This value should be set to the port address before any offset applied using the -Djboss.socket.binding.port-offset=xxx option in the startup script.



来源:https://stackoverflow.com/questions/25540892/java-sql-sqlexception-you-cannot-commit-during-a-managed-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!