问题
The Problem
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?
Weird Twist
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.
Environment
- Websphere 8.5.5
- MyEclipse Blue v10.x
- Windows 7 x64
Thoughts
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.
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).
Source Files
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>
Stack Trace
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
Final Thoughts
What would be different about these two ears that would make different code be called?
Thank you for any help you can provide!
回答1:
In hibernate 4.3 try:
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.WebSphereJtaPlatform" />
Seems to work
Note that this uses WebSphereJtaPlatform
as opposed to WebSphereExtendedJtaPlatform
.
来源:https://stackoverflow.com/questions/21196936/unsupportedoperationexception-when-using-jpa-hibernate-on-websphere