Set AutoCommit to false for Wildfly DataSource

爱⌒轻易说出口 提交于 2019-12-11 17:07:06

问题


I have tried to configure all sorts of datasources XA and non-XA, JTA and RESOURCE_LOCAL in Wildfly 14 for a local Postgresql DB. I am trying to deploy a JAR that uses a PersistenceUnitInfo and initialises a Datasource from the a InitialContext.

The problem now is that I cannot turn off Auto Commit in the datasource. Previously I was setting the defaultAutoCommit property in jetty-jnfi for a BasicDataSource type to false but I can't seem to a corresponding option in Wildfly config.

If not possible through Wildfly, how do I translate my jetty datasource config and where do I put it so that the Wildfly WS container looks at?

Previous jetty-jndi Config

<Configure id="Server" class="org.eclipse.jetty.server.Server">
    <New id="myLocalDB" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg></Arg>
        <Arg>jdbc/myLocalDB</Arg>
        <Arg>
            <New class="org.apache.commons.dbcp2.BasicDataSource">
                <Set name="driverClassName">org.postgresql.Driver</Set>
                <Set name="url">jdbc:postgresql://localhost:5432/my_local_db</Set>
                <Set name="username">user</Set>
                <Set name="password">***</Set>
                <Set name="defaultAutoCommit">false</Set>
            </New>
        </Arg>
    </New>
</Configure>

Current DataSource Initialiser within PersistenceUnitInfo

@Override
public DataSource getJtaDataSource() {
    try {
        Context ctx = (Context) new InitialContext().lookup("java:jboss/datasources");
        return (DataSource) ctx.lookup("myLocalDB");
    } catch (NamingException e) {
        e.printStackTrace();
        return null;
    }
}

来源:https://stackoverflow.com/questions/52249750/set-autocommit-to-false-for-wildfly-datasource

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