Set AutoCommit to false for Wildfly DataSource

2019-08-19 23:55发布

问题:

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;
    }
}