ClassCastException:com.ibm.ejs.container.UserTransactionWrapper Websphere 8.5.5 Hibernate 4.2.19

时间:2015-06-29 11:06:23

标签: java hibernate jpa websphere-8

我需要获得javax.transaction.UserTransaction,但在我尝试投降到com.ibm.ejs.container.UserTransactionWrapper时,我总是得到javax.transaction.UserTransaction我得ClassCastException 我正在使用:Websphere 8.5.5,Hibernate 4.19,Oracle 11g

我的persistence.xml

       <property name="transaction.manager_lookup_class"
            value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" />
        <property name="hibernate.transaction.factory_class"
            value="org.hibernate.transaction.JTATransactionFactory" />
        <property name="hibernate.jta.UserTransaction" value="java:comp/UserTransaction" />

的web.xml

<resource-ref>
    <res-ref-name>java:comp/UserTransaction</res-ref-name>
    <res-type>javax.transaction.UserTransaction</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

IBM的Web-bnd.xml

<resource-ref name="java:comp/UserTransaction" binding-name="java:comp/UserTransaction"></resource-ref>

我的服务

@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
 public class ResourceService {
 ...
private UserTransaction userTransaction;
...
this.userTransaction = (UserTransaction) new InitialContext()
     .lookup("java:comp/UserTransaction");

new InitialContext().lookup("java:comp/UserTransaction")始终获得com.ibm.ejs.container.UserTransactionWrapper个对象和

EJB threw an unexpected (non-declared) exception during invocation
of method "addResource" on bean "BeanId(testEar#test-0.0.1-SNAPSHOT.war#ResourceService, null)". Exception data: java.lang.ClassCas
tException: com.ibm.ejs.container.UserTransactionWrapper incompatible  with javax.transaction.UserTransaction

查找方法的实例我正在尝试通过

获取UserTransaction
@Resource(name="java:comp/UserTransaction")
private javax.transaction.UserTransaction userTransaction;
之后我得到

CNTR0019E: EJB threw an unexpected (non-declared) exception during invocation
of method "addResource". Exception data: javax.ejb.EJBException:  Injection failure; nested exception is: java.lang.IllegalArgumentE
xception: Can not set javax.transaction.UserTransaction field  pl.example.was.test.service.ResourceService.userTransaction to com.ibm
.ejs.container.UserTransactionWrapper

有人知道如何获得javax.transaction.UserTransaction?

感谢您的帮助

0 个答案:

没有答案