在Websphere上使用JPA/Hibernate时出现UnsupportedOperationException [英] UnsupportedOperationException When Using JPA/Hibernate On Websphere

查看:160
本文介绍了在Websphere上使用JPA/Hibernate时出现UnsupportedOperationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

尝试更新数据库中的记录时遇到以下异常:

I am getting the following exception when trying to update records in my database:

java.lang.UnsupportedOperationException
at org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter.setRollbackOnly(WebSphereExtendedJtaPlatform.java:139)....

此异常仅在更新时发生.创建,读取和删除工作正常.

This exception only happens when updating. Create, Read and Delete work fine.

引发此代码的典型原因是什么?

What are typical reasons for this code being thrown?

怪异曲折

我们必须使用MyEclipseBlue,并且不使用Maven或ant来构建项目.只能使用MyEclipseBlue的构建过程.测试由MyEclipseBlue生成的EAR时,抛出以上错误.当我在命令行上将代码部署为Maven生成的EAR时,不会抛出以上异常 .

We are required to use MyEclipseBlue and that Maven or ant is not used to build the project; only MyEclipseBlue's build process can be used. The above error is throw when testing an EAR that has been generated by MyEclipseBlue. The above exception is not thrown when I'm deploying the code as an EAR generated by Maven on the command line.

我花了很大的力气来验证所产生的战争是否相同,但是很明显,我缺少了一些东西.

I've taken enormous pains to verify that the generated wars are the same, but clearly, I'm missing something.

环境

  • Websphere 8.5.5
  • MyEclipse Blue v10.x
  • Windows 7 x64

想法

我不认为这是类加载的问题,因为引发异常的代码在hibernate-core.jar中.我还查看了Websphere管理控制台中的类路径报告.

I don't believe this is a matter of class loading because the code that throws the exception is in of hibernate-core.jar. I've also reviewed the classpaths report in Websphere's admin console.

这不是JDBC查找问题-两种版本都使用相同的方式连接到jndi资源.我目前同时部署了这两个服务器(之前我只有一个).

It's not a JDBC lookup issue--both versions use the same way to connect to a jndi resource. I have them both deployed at the same time presently (prior I just had one or the other).

源文件

在每次战争中,beans.xml(用于CDI)和persistence.xml文件完全相同:

The beans.xml (for CDI) and persistence.xml files are exactly the same in each war:

WEB-INF/class/META-INF/persistenc.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
        <persistence-unit name="boss-persistence" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>jdbc/boss</jta-data-source>
            <properties>
                <!--<property name="hibernate.hbm2ddl.auto" value="update"/>-->
                <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform"/>
                                    <property name="hibernate.format_sql" value="true"/>
                                    <property name="hibernate.show_sql" value="true"/>
            </properties>
        </persistence-unit>
    </persistence>

堆栈跟踪

Caused by: java.lang.UnsupportedOperationException
    at org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter.setRollbackOnly(WebSphereExtendedJtaPlatform.java:139)
    at org.hibernate.engine.transaction.internal.jta.CMTTransaction.markRollbackOnly(CMTTransaction.java:131)
    at org.hibernate.engine.transaction.internal.TransactionCoordinatorImpl.setRollbackOnly(TransactionCoordinatorImpl.java:306)
    at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.setRollbackOnly(SynchronizationCallbackCoordinatorImpl.java:127)
    at org.hibernate.engine.transaction.synchronization.internal.SynchronizationCallbackCoordinatorImpl.beforeCompletion(SynchronizationCallbackCoordinatorImpl.java:117)
    at org.hibernate.engine.transaction.synchronization.internal.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:53)
    at org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform$TransactionManagerAdapter$TransactionAdapter$1.invoke(WebSphereExtendedJtaPlatform.java:176)
    at com.sun.proxy.$Proxy127.beforeCompletion(Unknown Source)
    at com.ibm.ws.jtaextensions.SynchronizationCallbackWrapper.beforeCompletion(SynchronizationCallbackWrapper.java:66)
    at com.ibm.tx.jta.impl.RegisteredSyncs.coreDistributeBefore(RegisteredSyncs.java:291)
    at com.ibm.ws.tx.jta.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:153)
    at com.ibm.ws.tx.jta.TransactionImpl.prePrepare(TransactionImpl.java:2369)
    at com.ibm.ws.tx.jta.TransactionImpl.stage1CommitProcessing(TransactionImpl.java:577)
    at com.ibm.tx.jta.impl.TransactionImpl.processCommit(TransactionImpl.java:1015)
    ... 77 more

最终想法

这两个耳朵将产生不同的代码,这有什么不同?

What would be different about these two ears that would make different code be called?

感谢您提供的任何帮助!

Thank you for any help you can provide!

推荐答案

在Hibernate 4.3中尝试:

In hibernate 4.3 try:

<property name="hibernate.transaction.jta.platform"
    value="org.hibernate.service.jta.platform.internal.WebSphereJtaPlatform" />

似乎可以工作

请注意,它使用的是WebSphereJtaPlatform,而不是WebSphereExtendedJtaPlatform.

Note that this uses WebSphereJtaPlatform as opposed to WebSphereExtendedJtaPlatform.

这篇关于在Websphere上使用JPA/Hibernate时出现UnsupportedOperationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆