我目前对 JBoss 7 中 Oracle JNDI 数据源的自动提交设置有一个奇怪的情况。
大纲
我要部署的应用程序(我可以检查但不能更改)从连接池获取连接并尝试在某些语句之后提交。显然,默认情况下连接的自动提交设置为“true”,因此会引发异常。
You cannot commit with autocommit set!
我不能做什么
由于我无法更改应用程序源,因此以下“解决方案”不适用:
con.setAutoCommit(false);
我试过的
我查看了standalone.xml 的XML Schema,在数据源定义中发现了两个有希望的元素:
<connection-property name="autoCommit">
false
</connection-property>
但这被忽略了。
此外,我尝试使用具有以下属性的 xa-datasource:
<xa-datasource-property name="autoCommit">
false
</xa-datasource-property>
但是 autoCommit 属性属于连接,而不是数据源,因此会引发 PropertyNotFound 异常。
我的问题
如何在 JBoss7 下的 JNDI 数据源中将 Autocommit 设置为 false,我是否遗漏了什么?
我的定义
<datasource jta="false" jndi-name="java:/*****" pool-name="*****" enabled="true">
<connection-url>jdbc:oracle:thin:@****:****:****</connection-url>
<connection-property name="autoCommit">
false
</connection-property>
<driver>oracle.jdbc</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>*****</user-name>
<password>*****</password>
</security>
<timeout>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>1</idle-timeout-minutes>
</timeout>
</datasource>
更新
代码片段:
public AccessManager(jeeves.resources.dbms.Dbms dbms, SettingManager sm)
throws SQLException
{
List operList = dbms.select("SELECT * FROM Operations").getChildren();
}
更新 2
我要部署的应用程序是 Geonetwork CSW 2.9.0,以防万一有人有这方面的经验。我必须配置一个 JNDI 数据源,因为空间索引只发生在容器管理的连接上。
更新 3
堆栈跟踪:
15:52:18,203 ERROR [jeeves.engine] (MSC service thread 1-4) Raised exception while starting appl handler. Skipped.
15:52:18,205 ERROR [jeeves.engine] (MSC service thread 1-4) Handler : org.fao.geonet.Geonetwork
15:52:18,206 ERROR [jeeves.engine] (MSC service thread 1-4) Exception : java.sql.SQLException: You cannot commit with autocommit set!
15:52:18,210 ERROR [jeeves.engine] (MSC service thread 1-4) Message : You cannot commit with autocommit set!
15:52:18,213 ERROR [jeeves.engine] (MSC service thread 1-4) Stack : java.sql.SQLException: You cannot commit with autocommit set!
at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:984)
at org.jboss.jca.adapters.jdbc.WrappedConnection.commit(WrappedConnection.java:757)
at jeeves.resources.dbms.Dbms.commit(Dbms.java:150)
at jeeves.resources.dbms.AbstractDbmsPool.close(AbstractDbmsPool.java:158)
at jeeves.server.resources.ResourceManager.release(ResourceManager.java:302)
at jeeves.server.resources.ResourceManager.close(ResourceManager.java:270)
at jeeves.server.JeevesEngine.initAppHandler(JeevesEngine.java:556)
at jeeves.server.JeevesEngine.init(JeevesEngine.java:182)
at jeeves.server.sources.http.JeevesServlet.init(JeevesServlet.java:87)
at javax.servlet.GenericServlet.init(GenericServlet.java:242)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873)
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
更新 4
刚刚意识到 Jeeves DBMS 是一个简单的 JNDI 数据源包装器,它可以像任何人使用普通 JDBC 一样获取连接。所以我又回到了最初。