我正在编写一个在WebSphere Liberty Profile 8.5.5中运行的JEE7应用程序。我们正在使用JPA(通过WLP中的Eclipselink实现)。
我在同一个'persistence.xml'文件中有多个持久性单元。我还需要访问同一类中的两个单元。
当我尝试使用第二个EntityManager时,我收到运行时错误:
@PersistenceContext(unitName = "wwer-list")
private EntityManager entityManagerWwerList;
@PersistenceContext(unitName = "main-dashboard")
private EntityManager entityManagerMainDashboard;
E WTRN0062E: An illegal attempt to use multiple resources that have only one-phase capability has occurred within a global transaction.
如何摆脱此错误?
此外,我正在使用的所有表格仅供阅读。那么如何指定我只想要对JPA进行只读访问?
答案 0 :(得分:0)
此问题提示是因为您使用ConnectionPoolDataSource配置为(单阶段提交)的其中一个数据源配置了XADataSource。
如果您想继续使用相同的数据源配置,则必须将服务器配置更新为"接受启发式危害"。
在管理控制台中,单击EAR,选中复选框"接受启发式危险"。重新启动服务器。
启用最后参与者支持的此链接也可能有所帮助。 http://www.ibm.com/support/knowledgecenter/SSAW57_7.0.0/com.ibm.websphere.nd.doc/info/ae/webui_pme/ui/ueac_laoextensionsettings.html
答案 1 :(得分:0)
如果没有persistence.xml和server.xml配置,我无法确定,但支持<dataSource>
配置的javax.sql.XADataSource
元素看起来不支持XA。
默认情况下,javax.sql.ConnectionPoolDataSource
应该是javax.sql.DataSource
(因此支持XA),但是如果您使用的JDBC驱动程序不提供XADataSource实现,Liberty将选择更简单的DataSource实现(即UserTransaction.begin()
或普通commit()
)。
每当您发出rollback()
时,全局交易就会持续到您发出<dataSource type="javax.sql.XADataSource" ...>
<jdbcDriver .../>
<properties .../>
</dataSource>
或{{1}}为止。还有其他方法可以进入全局事务。
由于您需要只读访问权限,因此将DataSources转换为XA可能会过度。相反,尝试从等式中消除全局事务。如果无法消除全局事务,可以通过以下方式在server.xml中指定XADataSource:
{{1}}