-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 
Author Message
 Post subject: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Thu Nov 13, 2008 8:57 am 
Newbie

Joined: Thu Nov 13, 2008 7:23 am
Posts: 1
We have been using the included OpenJPA implementation in the EJB3 feature pack for WebSphere 6.1.0.19. Because of some limitations, we wish to use Hibernate EntityManager as a persistence provider instead. Our environment consists of the following:

Hibernate EntityManager version: 3.3.2.GA
Hibernate version: 3.2.6.ga
Hibernate Annotations version: 3.3.1.GA
WebSphere version:6.1.0.19 + EJB3 Feature Pack

Our project is built with Maven, and we use the existing maven artifacts for those. These artifacts and their dependencies are included in the generated EAR. We exclude the "ejb3-persistence" artifact explicitly, because this is provided by the server. On the WebSphere server, the class loader order is modified from "parent-first" to "child-first". (Basically, we followed the official WebSphere documentation on using an external persistence provider.) In the logs, we see that the Hibernate JPA provider is effectively in use.

We use the following settings in the persistence.xml configuration file:
Code:
<persistence-unit name="test_unit">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <jta-data-source>jdbc/Database</jta-data-source>
  <non-jta-data-source>jdbc/DatabaseNonJTA</non-jta-data-source>

  <class>org.test.AnEntity</class>
  <exclude-unlisted-classes>true</exclude-unlisted-classes>

  <properties>
      <property name="hibernate.dialect"
                      value="org.hibernate.dialect.InformixDialect"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>

    <property name="hibernate.transaction.factory_class"
                    value="org.hibernate.transaction.CMTTransactionFactory"/>

    <property name="hibernate.transaction.manager_lookup_class"
                   value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup"/>

    </properties>
  </persistence-unit>


We want to use container-managed transactions. The relevant settings in the configuration are factory_class and manager_lookup_class. These properties are configured as found in documentation by people from IBM: Using Spring and Hibernate with WebSphere Application Server. Also documentation on the Hibernate site itselfs confirms this. See the section "Transaction demarcation with EJB/CMT" on the following page: Sessions and transactions.

However, when using this configuration, we get the following warning when Hibernate processes the configuration: "org.hibernate.ejb.Ejb3Configuration prepareProperties Overriding hibernate.transaction.factory_class is dangerous, this might break the EJB3 specification implementation". If we just ignore this, and run our tests, we get another warning: "AbstractEntit W org.hibernate.ejb.AbstractEntityManagerImpl joinTransaction
Cannot join transaction: do not override hibernate.transaction.factory_class". It seems that read-only access to the database succeeds, but updates silently fail. We only get the warning.

Since the warning advises to not override the factory_class, and in addition, other documentation of hibernate explicitly states that factory_class should be set by hibernate itself (see section 4.2.2 Using JTA), and thus cannot be set manually, we dropped this from the configuration file. Still, this does not seem to give correct behaviour.

In one of our tests, we get an "OptimisticLockException". It seems that Hibernate wants to do a rollback, but we get the following exception:
Code:
AbstractEntit E org.hibernate.ejb.AbstractEntityManagerImpl throw PersistenceException
Unable to mark for rollback on PersistenceException:
java.lang.UnsupportedOperationException
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter.setRollbackOnly(WebSphereExtendedJTATransactionLookup.java:103)
at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:440)
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:595)
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:608)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:244)
at com.ibm.ws.jpa.management.JPAExEmInvocation.merge(JPAExEmInvocation.java:336)
at com.ibm.ws.jpa.management.JPAEntityManager.merge(JPAEntityManager.java:122)
...


When looking at the code for WebSphereExtendedJTATransactionLookup, it seems like most of the methods result in an UnsupportedOperationException. Is this normal or is the implementation of this class simply not complete?
Can anyone help with the correct settings for using Hibernate as JPA persistence provider in WebSphere, with container-managed transactions using JTA?

Any help greatly appreciated,
Ruben


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Thu Aug 27, 2009 10:24 am 
Newbie

Joined: Tue Aug 10, 2004 11:36 am
Posts: 3
Location: PA, USA
Ruben,

Did you ever resolve this issue? I am also running into this using spring and was 6.1 with hibernate.

Thanks,
Dan


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Wed Sep 02, 2009 6:36 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Is this problem only triggered when you move to container managed transactions? Will the same code run when you just issue transactions using Hibernate and a single threaded model?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Fri Apr 16, 2010 7:13 pm 
Newbie

Joined: Fri Apr 16, 2010 6:59 pm
Posts: 5
There doesn't seem to be an answer around yet, but I ran into this issue as well. Long story short: the WebSphereExtendedJTATransactionLookup does not support/use the > 6.1 WebSphereUowTransactionManager and instead relies on the non-public API's that have working in WAS 5.1, 6.0, etc.

rafealri has taken the effort to create a TransactionManagerLookup that is more compatible with the whole Ouw shebang: http://itdevworld.wordpress.com/2009/01 ... hibernate/ .

When I copy-paste this implementation, setRollbackOnly is implemented and the error we both encountered does not occur anymore.

Persistency.xml now looks as follows:
Code:
<persistence 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_1_0.xsd"
   version="1.0">
   <persistence-unit name="example-db">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:comp/env/jdbc/testDb</jta-data-source>
      <properties>
         <!-- WebSphere transaction manager lookup class -->
         <property name="hibernate.transaction.manager_lookup_class"
            value="com.rfc.example.tx.WebSphereUOWTransactionLookup" />
         <property name="hibernate.show.sql" value="true" />
         <property name="hibernate.cache.use_second_level_cache"
            value="false" />
         <property name="hibernate.hbm2ddl.auto" value="create-drop" />
      </properties>
   </persistence-unit>
</persistence>


And the class itself (all credit goes to rafaelri, I only hacked in the getTransactionIdentifier bit):
Code:
package com.rfc.example.tx;

import java.lang.reflect.Method;
import java.util.Properties;

import javax.naming.NamingException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.InvalidTransactionException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.xa.XAResource;

import org.hibernate.HibernateException;
import org.hibernate.transaction.TransactionManagerLookup;
import org.hibernate.util.NamingHelper;
import org.omg.CORBA.SystemException;

/**
* @author rafaelri
* Support for proprietary interfaces for registering synchronizations in WebSphere 6.1+
*/
public class WebSphereUOWTransactionLookup implements TransactionManagerLookup {

   private static final String UOW_MANAGER_JNDI = "java:comp/websphere/UOWManager";
   private static final String UOW_SYNCHRONIZATION_MANAGER_JNDI = "java:comp/websphere/UOWSynchronizationRegistry";
   public TransactionManager getTransactionManager(Properties props)
   throws HibernateException {
      return new TransactionManagerAdapter(props);
   }

   public String getUserTransactionName() {
      return "java:comp/UserTransaction";
   }

   public static class TransactionManagerAdapter implements TransactionManager {

      private final Object uowManager;
      private final Class uowManagerClass;
      private final Object uowSynchronizationRegistry;
      private final Class uowSynchronizationRegistryClass;
      private final Method registerSynchronizationMethod;
      private final Method setRollbackOnlyMethod;

      private final Properties properties;
      private final Method getLocalIdMethod;

      private TransactionManagerAdapter(Properties props) {
         this.properties = props;
         try {
            uowManager = NamingHelper.getInitialContext(props).lookup( UOW_MANAGER_JNDI );
            uowManagerClass = Class.forName("com.ibm.ws.uow.UOWManager");
            setRollbackOnlyMethod = uowManagerClass.getMethod(
                  "setRollbackOnly",
                  new Class[] {}
               );

            uowSynchronizationRegistry = NamingHelper.getInitialContext(props).lookup( UOW_SYNCHRONIZATION_MANAGER_JNDI );
            uowSynchronizationRegistryClass = Class.forName("com.ibm.websphere.uow.UOWSynchronizationRegistry");

            registerSynchronizationMethod = uowSynchronizationRegistryClass.getMethod(
                  "registerInterposedSynchronization",
                  new Class[] { Synchronization.class }
               );
            Class extendedJTATransactionClass = Class.forName("com.ibm.websphere.jtaextensions.ExtendedJTATransaction");
            getLocalIdMethod = extendedJTATransactionClass.getMethod( "getLocalId", null );

         }
         catch (ClassNotFoundException cnfe) {
            throw new HibernateException(cnfe);
         }
         catch (NoSuchMethodException nsme) {
            throw new HibernateException(nsme);
         } catch (NamingException ne) {
            throw new HibernateException(ne);
         }
      }

      public void begin() throws NotSupportedException, SystemException {
         throw new UnsupportedOperationException();
      }

      public void commit() throws RollbackException, HeuristicMixedException,
            HeuristicRollbackException, SecurityException,
            IllegalStateException, SystemException {
         throw new UnsupportedOperationException();
      }

      public int getStatus() throws SystemException {
         throw new UnsupportedOperationException();
      }

      public Transaction getTransaction() throws SystemException {
         return new TransactionAdapter(properties);
      }

      public void resume(Transaction txn) throws  InvalidTransactionException,
            IllegalStateException, SystemException {
         throw new UnsupportedOperationException();
      }

      public void rollback() throws IllegalStateException, SecurityException,
            SystemException {
         throw new UnsupportedOperationException();
      }

      public void setRollbackOnly() throws IllegalStateException,
            SystemException {
         try {
            setRollbackOnlyMethod.invoke(
               uowManager,
               new Object[] { }
            );
         }
         catch (Exception e) {
            throw new HibernateException(e);
         }
      }

      public void setTransactionTimeout(int i) throws SystemException {
         throw new UnsupportedOperationException();
      }

      public Transaction suspend() throws SystemException {
         throw new UnsupportedOperationException();
      }

      public class TransactionAdapter implements Transaction {

         private final Object extendedJTATransaction;

         private TransactionAdapter(Properties props) {
            try {
               extendedJTATransaction = NamingHelper.getInitialContext(props)
                  .lookup("java:comp/websphere/ExtendedJTATransaction");

            }
            catch (NamingException ne) {
               throw new HibernateException(ne);
            }
         }

         public void registerSynchronization(final Synchronization synchronization)
               throws RollbackException, IllegalStateException,
               SystemException {

            try {
               registerSynchronizationMethod.invoke(
                     uowSynchronizationRegistry,
                     new Object[] { synchronization }
                  );
            }
            catch (Exception e) {
               throw new HibernateException(e);
            }

         }

         public int hashCode() {
            return getLocalId().hashCode();
         }

         public boolean equals(Object other) {
            if ( !(other instanceof TransactionAdapter) ) return false;
            TransactionAdapter that = (TransactionAdapter) other;
            return getLocalId().equals( that.getLocalId() );
         }

         private Object getLocalId() {
            try {
               return getLocalIdMethod.invoke(extendedJTATransaction, null);
            }
            catch (Exception e) {
               throw new HibernateException(e);
            }
         }

         public void commit() throws RollbackException, HeuristicMixedException,
               HeuristicRollbackException, SecurityException,
               IllegalStateException, SystemException {
            throw new UnsupportedOperationException();
         }

         public boolean delistResource(XAResource resource, int i)
               throws IllegalStateException, SystemException {
            throw new UnsupportedOperationException();
         }

         public boolean enlistResource(XAResource resource)
               throws RollbackException, IllegalStateException,
               SystemException {
            throw new UnsupportedOperationException();
         }

         public int getStatus() throws SystemException {
            return new Integer(0).equals( getLocalId() ) ?
                  Status.STATUS_NO_TRANSACTION : Status.STATUS_ACTIVE;
         }

         public void rollback() throws IllegalStateException, SystemException {
            throw new UnsupportedOperationException();
         }

         public void setRollbackOnly() throws IllegalStateException,
               SystemException {
            try {
               setRollbackOnlyMethod.invoke(
                  uowManager,
                  new Object[] { }
               );
            }
            catch (Exception e) {
               throw new HibernateException(e);
            }
         }
      }
      
   }

   /**
    * {@inheritDoc}
    */
   public Object getTransactionIdentifier(Transaction transaction) {
      // WebSphere, however, is not a sane JEE/JTA container...
      return new Integer( transaction.hashCode() );
   }

}


I'm curious if there are just that little users that use WAS > 6.1 in combination with JPA1.0 and Hibernate or that we're the only ones testing if our OptimisticLocking works as expected ;)

Maybe I should post an issue on the Hibernate JIRA to request this issue to be addressed? Or am I overlooking something silly? Or am I using Hibernate/JPA/Spring/Websphere completely wrong? :)


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Fri Apr 16, 2010 7:15 pm 
Newbie

Joined: Fri Apr 16, 2010 6:59 pm
Posts: 5
Oh by the way; this is in WAS7 / IBM JDK 6.


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Sat Apr 17, 2010 9:18 am 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
VincentL wrote:
There doesn't seem to be an answer around yet, but I ran into this issue as well. Long story short: the WebSphereExtendedJTATransactionLookup does not support/use the > 6.1 WebSphereUowTransactionManager and instead relies on the non-public API's that have working in WAS 5.1, 6.0, etc.

rafaelri has taken the effort to create a TransactionManagerLookup that is more compatible with the whole Ouw shebang: http://itdevworld.wordpress.com/2009/01 ... hibernate/ .

I'm curious if there are just that little users that use WAS > 6.1 in combination with JPA1.0 and Hibernate or that we're the only ones testing if our OptimisticLocking works as expected ;)

Maybe I should post an issue on the Hibernate JIRA to request this issue to be addressed? Or am I overlooking something silly? Or am I using Hibernate/JPA/Spring/Websphere completely wrong? :)


Vincent, I tried to submit my patch but it didn't seem to draw much attention (http://hibernate.jira.com/browse/HHH-2703) may be if you guys reinforce this need we can get it integrated...

Good to hear that it this piece of code was useful :D

_________________
Rafael Ribeiro


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Sat Apr 17, 2010 12:38 pm 
Newbie

Joined: Fri Apr 16, 2010 6:59 pm
Posts: 5
Interesting. The issue you reference makes a lot of stuff more clear.

Regarding the implementation: shouldn't the ExtendedJTA thingie be completely removed now? It's only used for getLocalId now - this can be pointed to getUowLocalId (on the UOWManager) instead probably. And the getStatus to getUowStatus? Pretty much like in the Spring implementation. It seems shaky to mix the UOWManager and the ExtendedJTATransaction. That's the entire reason I went looking for this: Spring uses the UOWManager and Hibernate the ExtendedJTATransaction, I felt like I was asking for trouble :) Or should mixing these two implementation be completely fine?

Oh and another thing - the UOWSynchronizationRegistry interface is implemented by the UOWManager. It probably isn't needed to resolve it separately, the UOWManager should be able to do everything (see here).

And slighty off topic: I'm still confused as to what Hibernate is going to do exactly with the JTATransaction since it's using the JoinableCMT implementation.. is this UnsupportedOperationException actually a problem? Isn't this cause exception (OptimisticLockingException) catched by the Spring AOP anyways which will trigger a rollback (see Jpa spec)? Or, in other words, it's nice that we'd like Hibernate to use the official, public WAS API but is there an actual problem here or not?

Difficult questions on a beautiful saturday afternoon best spent outside in the sun ;)


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Sat Apr 17, 2010 5:13 pm 
Newbie

Joined: Fri Apr 16, 2010 6:59 pm
Posts: 5
VincentL wrote:
Or, in other words, it's nice that we'd like Hibernate to use the official, public WAS API but is there an actual problem here or not?

Let's answer that question. Nothing like a little test, right? I set the IBM uow package debug to finest to determine if a rollback is done.

With the modded OUW transaction manager lookup code:
Code:
[17-4-10 22:57:36:692 CEST] 00000015 AbstractEntit 1 org.slf4j.impl.JCLLoggerAdapter debug mark transaction for rollback
[17-4-10 22:57:36:692 CEST] 00000015 UOWManagerImp >  setRollbackOnly Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 22:57:36:692 CEST] 00000015 UOWManagerImp >  getUOWScope Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 22:57:36:692 CEST] 00000015 UOWManagerImp <  getUOWScope Exit
                                 com.ibm.ws.tx.jta.TransactionImpl@110f110f#tid=4
[17-4-10 22:57:36:692 CEST] 00000015 UOWManagerImp <  setRollbackOnly Exit
[17-4-10 22:57:36:692 CEST] 00000015 RuleBasedTran 3 org.springframework.transaction.interceptor.RuleBasedTransactionAttribute rollbackOn Applying rules to determine whether transaction should rollback on javax.persistence.OptimisticLockException: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.rfc.example.domain.User#1271537847847]
[17-4-10 22:57:36:692 CEST] 00000015 RuleBasedTran 3 org.springframework.transaction.interceptor.RuleBasedTransactionAttribute rollbackOn Winning rollback rule is: null
[17-4-10 22:57:36:692 CEST] 00000015 RuleBasedTran 3 org.springframework.transaction.interceptor.RuleBasedTransactionAttribute rollbackOn No relevant rollback rule found: applying default rules
[17-4-10 22:57:36:692 CEST] 00000015 WebSphereUowT 3 org.springframework.transaction.support.AbstractPlatformTransactionManager triggerBeforeCompletion Triggering beforeCompletion synchronization
[17-4-10 22:57:36:692 CEST] 00000015 TransactionSy 3 org.springframework.transaction.support.TransactionSynchronizationManager clearSynchronization Clearing transaction synchronization
[17-4-10 22:57:36:692 CEST] 00000015 UOWManagerImp >  registerInterposedSynchronization Entry
                                 org.springframework.transaction.jta.JtaAfterCompletionSynchronization@5cdb5cdb
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 22:57:36:692 CEST] 00000015 UOWManagerImp >  getUOWScope Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 22:57:36:692 CEST] 00000015 UOWManagerImp <  getUOWScope Exit
                                 com.ibm.ws.tx.jta.TransactionImpl@110f110f#tid=4
[17-4-10 22:57:36:692 CEST] 00000015 ComponentCont >  ComponentContextSynchronizationWrapper Entry
                                 org.springframework.transaction.jta.JtaAfterCompletionSynchronization@5cdb5cdb
[17-4-10 22:57:36:692 CEST] 00000015 ComponentCont >  captureComponentContext Entry
                                 com.ibm.ws.uow.ComponentContextSynchronizationWrapper@62ef62ef
[17-4-10 22:57:36:692 CEST] 00000015 ComponentCont <  captureComponentContext Exit
[17-4-10 22:57:36:692 CEST] 00000015 ComponentCont <  ComponentContextSynchronizationWrapper Exit
                                 com.ibm.ws.uow.ComponentContextSynchronizationWrapper@62ef62ef
[17-4-10 22:57:36:692 CEST] 00000015 UOWManagerImp <  registerInterposedSynchronization Exit
[17-4-10 22:57:36:708 CEST] 00000015 DMAdapter     I com.ibm.ws.ffdc.impl.DMAdapter getAnalysisEngine FFDC1009I: Analysis Engine using data base: e:\java\IBM\WebSphere\AppServer\profiles\AppSrv01\properties\logbr\ffdc\adv\ffdcdb.xml
[17-4-10 22:57:36:895 CEST] 00000015 FfdcProvider  I com.ibm.ws.ffdc.impl.FfdcProvider logIncident FFDC1003I: FFDC Incident emitted on e:\java\IBM\WebSphere\AppServer\profiles\AppSrv01\logs\ffdc\server1_45ee45ee_10.04.17_22.57.36.69246975.txt com.ibm.ws.uow.UOWManagerImpl.runUnderNewUOW 934
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp >  setRollbackOnly Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp >  getUOWScope Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp <  getUOWScope Exit
                                 com.ibm.ws.tx.jta.TransactionImpl@110f110f#tid=4
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp <  setRollbackOnly Exit
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp >  uowEnd Entry
                                 com.ibm.ws.tx.jta.TransactionImpl@110f110f#tid=4
                                 1
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp >  getRollbackOnly Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp >  getUOWScope Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp <  getUOWScope Exit
                                 com.ibm.ws.tx.jta.TransactionImpl@110f110f#tid=4
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp <  getRollbackOnly Exit
                                 true
[17-4-10 22:57:36:895 CEST] 00000015 UOWManagerImp >  uowRollback Entry
                                 1
[17-4-10 22:57:36:895 CEST] 00000015 UOWScopeCallb >  notifyCallbacks Entry
                                 2
                                 com.ibm.ws.tx.jta.TransactionImpl@110f110f#tid=4
                                 com.ibm.ws.uow.UOWScopeCallbackManager@65186518
[17-4-10 22:57:36:895 CEST] 00000015 UOWScopeCallb <  notifyCallbacks Exit
[17-4-10 22:57:36:895 CEST] 00000015 ComponentCont >  afterCompletion Entry
                                 4
                                 com.ibm.ws.uow.ComponentContextSynchronizationWrapper@38813881
[17-4-10 22:57:36:895 CEST] 00000015 ComponentCont >  setComponentContextOnThread Entry
                                 com.ibm.ws.uow.ComponentContextSynchronizationWrapper@38813881
[17-4-10 22:57:36:895 CEST] 00000015 ComponentCont <  setComponentContextOnThread Exit
[17-4-10 22:57:36:895 CEST] 00000015 CacheSynchron 3 org.slf4j.impl.JCLLoggerAdapter trace transaction after completion callback, status: 4
[17-4-10 22:57:36:895 CEST] 00000015 JDBCContext   3 org.slf4j.impl.JCLLoggerAdapter trace after transaction completion
[17-4-10 22:57:36:895 CEST] 00000015 SessionImpl   3 org.slf4j.impl.JCLLoggerAdapter trace after transaction completion


With default ExtendedJTA stuff
Code:
[17-4-10 23:02:20:113 CEST] 00000019 AbstractEntit 1 org.slf4j.impl.JCLLoggerAdapter debug mark transaction for rollback
[17-4-10 23:02:20:113 CEST] 00000019 AbstractEntit E org.slf4j.impl.JCLLoggerAdapter error Unable to mark for rollback on PersistenceException:
                                 java.lang.UnsupportedOperationException
   at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter.setRollbackOnly(WebSphereExtendedJTATransactionLookup.java:161)
   at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:421)
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:576)
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:589)
   at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:244)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
   at java.lang.reflect.Method.invoke(Method.java:599)
   at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:358)
   at $Proxy49.merge(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
   at java.lang.reflect.Method.invoke(Method.java:599)
   at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:198)
   at $Proxy45.merge(Unknown Source)
   at com.rfc.example.dao.UserDao.doStuffC(UserDao.java:72)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
   at java.lang.reflect.Method.invoke(Method.java:599)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
   at org.springframework.transaction.interceptor.TransactionInterceptor$1.doInTransaction(TransactionInterceptor.java:128)
   at org.springframework.transaction.jta.WebSphereUowTransactionManager$UOWActionAdapter.run(WebSphereUowTransactionManager.java:306)
   at com.ibm.ws.uow.UOWManagerImpl.runUnderNewUOW(UOWManagerImpl.java:1065)
   at com.ibm.ws.uow.UOWManagerImpl.runUnderUOW(UOWManagerImpl.java:626)
   at org.springframework.transaction.jta.WebSphereUowTransactionManager.execute(WebSphereUowTransactionManager.java:252)
<snip>
   at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1527)

[17-4-10 23:02:20:129 CEST] 00000019 RuleBasedTran 3 org.springframework.transaction.interceptor.RuleBasedTransactionAttribute rollbackOn Applying rules to determine whether transaction should rollback on javax.persistence.OptimisticLockException: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.rfc.example.domain.User#1271538123234]
[17-4-10 23:02:20:129 CEST] 00000019 RuleBasedTran 3 org.springframework.transaction.interceptor.RuleBasedTransactionAttribute rollbackOn Winning rollback rule is: null
[17-4-10 23:02:20:129 CEST] 00000019 RuleBasedTran 3 org.springframework.transaction.interceptor.RuleBasedTransactionAttribute rollbackOn No relevant rollback rule found: applying default rules
[17-4-10 23:02:20:129 CEST] 00000019 WebSphereUowT 3 org.springframework.transaction.support.AbstractPlatformTransactionManager triggerBeforeCompletion Triggering beforeCompletion synchronization
[17-4-10 23:02:20:129 CEST] 00000019 TransactionSy 3 org.springframework.transaction.support.TransactionSynchronizationManager clearSynchronization Clearing transaction synchronization
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp >  registerInterposedSynchronization Entry
                                 org.springframework.transaction.jta.JtaAfterCompletionSynchronization@1c411c41
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp >  getUOWScope Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp <  getUOWScope Exit
                                 com.ibm.ws.tx.jta.TransactionImpl@6dfb6dfb#tid=7
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont >  ComponentContextSynchronizationWrapper Entry
                                 org.springframework.transaction.jta.JtaAfterCompletionSynchronization@1c411c41
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont >  captureComponentContext Entry
                                 com.ibm.ws.uow.ComponentContextSynchronizationWrapper@21192119
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont <  captureComponentContext Exit
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont <  ComponentContextSynchronizationWrapper Exit
                                 com.ibm.ws.uow.ComponentContextSynchronizationWrapper@21192119
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp <  registerInterposedSynchronization Exit
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp >  setRollbackOnly Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp >  getUOWScope Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp <  getUOWScope Exit
                                 com.ibm.ws.tx.jta.TransactionImpl@6dfb6dfb#tid=7
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp <  setRollbackOnly Exit
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp >  uowEnd Entry
                                 com.ibm.ws.tx.jta.TransactionImpl@6dfb6dfb#tid=7
                                 1
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp >  getRollbackOnly Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp >  getUOWScope Entry
                                 com.ibm.ws.uow.UOWManagerImpl@298a298a
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp <  getUOWScope Exit
                                 com.ibm.ws.tx.jta.TransactionImpl@6dfb6dfb#tid=7
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp <  getRollbackOnly Exit
                                 true
[17-4-10 23:02:20:129 CEST] 00000019 UOWManagerImp >  uowRollback Entry
                                 1
[17-4-10 23:02:20:129 CEST] 00000019 UOWScopeCallb >  notifyCallbacks Entry
                                 2
                                 com.ibm.ws.tx.jta.TransactionImpl@6dfb6dfb#tid=7
                                 com.ibm.ws.uow.UOWScopeCallbackManager@65186518
[17-4-10 23:02:20:129 CEST] 00000019 UOWScopeCallb <  notifyCallbacks Exit
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont >  afterCompletion Entry
                                 4
                                 com.ibm.ws.uow.ComponentContextSynchronizationWrapper@21192119
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont >  setComponentContextOnThread Entry
                                 com.ibm.ws.uow.ComponentContextSynchronizationWrapper@21192119
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont <  setComponentContextOnThread Exit
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont >  removeComponentContextFromThread Entry
                                 com.ibm.ws.uow.ComponentContextSynchronizationWrapper@21192119
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont <  removeComponentContextFromThread Exit
[17-4-10 23:02:20:129 CEST] 00000019 ComponentCont <  afterCompletion Exit
[17-4-10 23:02:20:129 CEST] 00000019 CacheSynchron 3 org.slf4j.impl.JCLLoggerAdapter trace transaction after completion callback, status: 5
[17-4-10 23:02:20:129 CEST] 00000019 JDBCContext   3 org.slf4j.impl.JCLLoggerAdapter trace after transaction completion
[17-4-10 23:02:20:129 CEST] 00000019 SessionImpl   3 org.slf4j.impl.JCLLoggerAdapter trace after transaction completion


Both situations clearly trigger: "UOWManagerImp > uowRollback Entry". I'm satisfied :)


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Sat Apr 17, 2010 5:31 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
VincentL wrote:
Interesting. The issue you reference makes a lot of stuff more clear.

This was my starting point :D

VincentL wrote:
Regarding the implementation: shouldn't the ExtendedJTA thingie be completely removed now? It's only used for getLocalId now - this can be pointed to getUowLocalId (on the UOWManager) instead probably. And the getStatus to getUowStatus? Pretty much like in the Spring implementation. It seems shaky to mix the UOWManager and the ExtendedJTATransaction. That's the entire reason I went looking for this: Spring uses the UOWManager and Hibernate the ExtendedJTATransaction, I felt like I was asking for trouble :) Or should mixing these two implementation be completely fine?

I remember getting a zero for transaction id under a certain circumstance I guess using the uowLocalId (forgive me for not remembering right now... it was more than an year ago. I can give a try on this monday at work since I have no WAS installed at home). But I agree that we could move away from this... I guess it is even safer cause I can expect IBM to drop this API soon without any warning shot :D

VincentL wrote:
Oh and another thing - the UOWSynchronizationRegistry interface is implemented by the UOWManager. It probably isn't needed to resolve it separately, the UOWManager should be able to do everything (see here).

And slighty off topic: I'm still confused as to what Hibernate is going to do exactly with the JTATransaction since it's using the JoinableCMT implementation.. is this UnsupportedOperationException actually a problem? Isn't this cause exception (OptimisticLockingException) catched by the Spring AOP anyways which will trigger a rollback (see Jpa spec)? Or, in other words, it's nice that we'd like Hibernate to use the official, public WAS API but is there an actual problem here or not?

Difficult questions on a beautiful saturday afternoon best spent outside in the sun ;)

I'll have a look at the links you provided... another thing I remember from the time I did this was that there were classes with similar names under different packages... one seemed to be the "almost public" class for us to use and another one seemed to be a WAS internal...

_________________
Rafael Ribeiro


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Mon Apr 19, 2010 12:17 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
Vincent,

Any news? Any progress? Do you have any simple FooBar alike test case package that you could share? (I wasnt really willing to setup our application over here since it requires way too much resources...)
Have you checked it in fact "java:comp/websphere/UOWManager" and "java:comp/websphere/UOWSynchronizationRegistry" point to the same implementation class?
And sincerely I really remember having problems using getLocalUOWId for Transaction.getLocalId.

regards,

_________________
Rafael Ribeiro


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Mon Apr 19, 2010 3:52 pm 
Newbie

Joined: Fri Apr 16, 2010 6:59 pm
Posts: 5
Hi Rafael,

Yep, I have a simple app I can share. I'll put it up somewhere as soon as I can, expect somewhere tomorrow. Or PM me a email address and I'll drop you as zip. Or send me an email, I posted on your blog so you should have it :P

I do not know for certain if the classes at those JNDI location are indeed the same, but the code in the Spring UOW seems to call methods on both interface. Should be ok, but still, I could be wrong.

Don't really have any more progress to report. We've reverted to the ExtendedJTA thingy for now, since it's in Hibernate and presumably used in production environments and my test indicate that the rollback does in fact succeed. It still feels shaky, so I'll be happy to contribute to a UOW-based implementation for Hibernate.


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Mon Apr 19, 2010 4:28 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
VincentL wrote:
Hi Rafael,

Yep, I have a simple app I can share. I'll put it up somewhere as soon as I can, expect somewhere tomorrow. Or PM me a email address and I'll drop you as zip. Or send me an email, I posted on your blog so you should have it :P

Done...
VincentL wrote:
I do not know for certain if the classes at those JNDI location are indeed the same, but the code in the Spring UOW seems to call methods on both interface. Should be ok, but still, I could be wrong.

I'll debug and check....

VincentL wrote:
Don't really have any more progress to report. We've reverted to the ExtendedJTA thingy for now, since it's in Hibernate and presumably used in production environments and my test indicate that the rollback does in fact succeed. It still feels shaky, so I'll be happy to contribute to a UOW-based implementation for Hibernate.

Same reason I reverted back... I dont know about your app but mine is a financial one and we cant risk a thing...
but sincerely... havent you considered in your case that it is rolling back cause in the end an uncatched exception might be crossing an EJB and as a side effect triggering the rollback (along with SessionBean removal and a lot of other side effects) ?

regards,

_________________
Rafael Ribeiro


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Wed May 05, 2010 2:27 am 
Newbie

Joined: Mon Mar 29, 2010 10:45 pm
Posts: 6
Hi Rafael & Vincent,

I bumped across this post, while in search of fixing an issue relavant to the usage of WebSphereExtendedJTATransactionLookup. I was looking at the code where hibernate's implementation of Isolater in conjunction with the TransactionManager tries to suspend a transaction for creation of incremental primary keys using - @TableGenerator. [ultimately resulting in unsupported exception]

WebSphereExtendedJTATransactionLookup throws an unsupported exception, while the old WebsphereTransactionManagerLookiup works perfectly fine. I had raised a jira on this issue as well as made a post in the forum.

http://opensource.atlassian.com/project ... e/HHH-5019
viewtopic.php?f=1&t=1003723&start=0

We have the exact same configuration of EJB3 feature pack, hibernate and websphere app server. I am not sure on how to proceed with this. I see that you have a deep insight on the transaction management issues with hibernate and websphere and request your help on any pointers on this.

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Wed Mar 06, 2013 4:45 am 
Newbie

Joined: Fri Sep 21, 2007 11:55 am
Posts: 4
Thanks very much for the class Rafael !

I've just updated it for WAS 8 and Hibernate 4.0.1.

To use it :

Code:
<persistence 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"
   version="2.0">
   <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>jdbc/Aws</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="${hibernate.dialect}" />
         <property name="hibernate.max_fetch_depth" value="3" />
         <property name="hibernate.hbm2ddl.auto" value="update" />
         <property name="hibernate.show_sql" value="true" />
         <property name="hibernate.transaction.jta.platform" value="com.rfc.example.tx.WebSphereUOWTransactionLookup" />
      </properties>
   </persistence-unit>
</persistence>


And here's the class (I also implemented getStatus()) :
Code:
package com.rfc.example.tx;

import java.lang.reflect.Method;

import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.InvalidTransactionException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;
import javax.transaction.xa.XAResource;

import org.hibernate.HibernateException;
import org.hibernate.service.jta.platform.internal.AbstractJtaPlatform;

/**
* @author rafaelri Support for proprietary interfaces for registering
*         synchronizations in WebSphere 6.1+
*/
public class WebSphereUOWTransactionLookup extends AbstractJtaPlatform {

   private static final long serialVersionUID = 6514686920271789210L;
   private static final String UOW_MANAGER_JNDI = "java:comp/websphere/UOWManager";
   private static final String UOW_SYNCHRONIZATION_MANAGER_JNDI = "java:comp/websphere/UOWSynchronizationRegistry";
   public static final String UT_NAME = "java:comp/UserTransaction";

   @Override
   protected TransactionManager locateTransactionManager() {
      return new TransactionManagerAdapter();
   }

   @Override
   protected UserTransaction locateUserTransaction() {
      return (UserTransaction) jndiService().locate(UT_NAME);
   }

   public class TransactionManagerAdapter implements TransactionManager {

      private final Class uowManagerClass;
      private final Class uowSynchronizationRegistryClass;
      private Object uowManager;
      private Object uowSynchronizationRegistry;
      private final Method registerSynchronizationMethod;
      private final Method setRollbackOnlyMethod;

      private final Method getLocalIdMethod;

      @SuppressWarnings({ "unchecked", "rawtypes" })
      private TransactionManagerAdapter() {
         try {
            uowManagerClass = Class.forName("com.ibm.ws.uow.UOWManager");
            setRollbackOnlyMethod = uowManagerClass.getMethod(
                  "setRollbackOnly", new Class[] {});

            uowSynchronizationRegistryClass = Class
                  .forName("com.ibm.websphere.uow.UOWSynchronizationRegistry");

            registerSynchronizationMethod = uowSynchronizationRegistryClass
                  .getMethod("registerInterposedSynchronization",
                        new Class[] { Synchronization.class });
            Class extendedJTATransactionClass = Class
                  .forName("com.ibm.websphere.jtaextensions.ExtendedJTATransaction");
            getLocalIdMethod = extendedJTATransactionClass.getMethod(
                  "getLocalId", null);

         } catch (ClassNotFoundException cnfe) {
            throw new HibernateException(cnfe);
         } catch (NoSuchMethodException nsme) {
            throw new HibernateException(nsme);
         }
      }

      /**
       * Lazily loaded because UOW_MANAGER_JNDI isn't always available on
       * Hibernate startup (when
       * HibernatePersistence.createContainerEntityManagerFactory is called).
       */
      private Object getUowManager() {
         if (uowManager == null) {
            uowManager = jndiService().locate(UOW_MANAGER_JNDI);
         }
         return uowManager;
      }

      private Object getUowSynchronizationRegistry() {
         if (uowSynchronizationRegistry == null) {
            uowSynchronizationRegistry = jndiService().locate(UOW_SYNCHRONIZATION_MANAGER_JNDI);
         }
         return uowSynchronizationRegistry;
      }

      public void begin() throws NotSupportedException, SystemException {
         throw new UnsupportedOperationException();
      }

      public void commit() throws RollbackException, HeuristicMixedException,
            HeuristicRollbackException, SecurityException,
            IllegalStateException, SystemException {
         throw new UnsupportedOperationException();
      }

      @Override
      public int getStatus() throws SystemException {
         return getTransaction() == null ? Status.STATUS_NO_TRANSACTION
               : getTransaction().getStatus();
      }

      public Transaction getTransaction() throws SystemException {
         return new TransactionAdapter();
      }

      public void resume(Transaction txn) throws InvalidTransactionException,
            IllegalStateException, SystemException {
         throw new UnsupportedOperationException();
      }

      public void rollback() throws IllegalStateException, SecurityException,
            SystemException {
         throw new UnsupportedOperationException();
      }

      public void setRollbackOnly() throws IllegalStateException,
            SystemException {
         try {
            setRollbackOnlyMethod.invoke(getUowManager(), new Object[] {});
         } catch (Exception e) {
            throw new HibernateException(e);
         }
      }

      public void setTransactionTimeout(int i) throws SystemException {
         throw new UnsupportedOperationException();
      }

      public Transaction suspend() throws SystemException {
         throw new UnsupportedOperationException();
      }

      public class TransactionAdapter implements Transaction {

         private final Object extendedJTATransaction;

         private TransactionAdapter() {
            extendedJTATransaction = jndiService().locate(
                  "java:comp/websphere/ExtendedJTATransaction");
         }

         public void registerSynchronization(
               final Synchronization synchronization)
               throws RollbackException, IllegalStateException,
               SystemException {

            try {
               registerSynchronizationMethod.invoke(
                     getUowSynchronizationRegistry(),
                     new Object[] { synchronization });
            } catch (Exception e) {
               throw new HibernateException(e);
            }

         }

         public int hashCode() {
            return getLocalId().hashCode();
         }

         public boolean equals(Object other) {
            if (!(other instanceof TransactionAdapter))
               return false;
            TransactionAdapter that = (TransactionAdapter) other;
            return getLocalId().equals(that.getLocalId());
         }

         private Object getLocalId() {
            try {
               return getLocalIdMethod
                     .invoke(extendedJTATransaction, null);
            } catch (Exception e) {
               throw new HibernateException(e);
            }
         }

         public void commit() throws RollbackException,
               HeuristicMixedException, HeuristicRollbackException,
               SecurityException, IllegalStateException, SystemException {
            throw new UnsupportedOperationException();
         }

         public boolean delistResource(XAResource resource, int i)
               throws IllegalStateException, SystemException {
            throw new UnsupportedOperationException();
         }

         public boolean enlistResource(XAResource resource)
               throws RollbackException, IllegalStateException,
               SystemException {
            throw new UnsupportedOperationException();
         }

         public int getStatus() throws SystemException {
            return new Integer(0).equals(getLocalId()) ? Status.STATUS_NO_TRANSACTION
                  : Status.STATUS_ACTIVE;
         }

         public void rollback() throws IllegalStateException,
               SystemException {
            throw new UnsupportedOperationException();
         }

         public void setRollbackOnly() throws IllegalStateException,
               SystemException {
            try {
               setRollbackOnlyMethod.invoke(getUowManager(), new Object[] {});
            } catch (Exception e) {
               throw new HibernateException(e);
            }
         }
      }

   }

   /**
    * {@inheritDoc}
    */
   public Object getTransactionIdentifier(Transaction transaction) {
      // WebSphere, however, is not a sane JEE/JTA container...
      return new Integer(transaction.hashCode());
   }
}


N.B : I added a comment in your blog http://itdevworld.wordpress.com/2009/01/23/websphere-uow-transactionmanagerlookup-for-hibernate


Top
 Profile  
 
 Post subject: Re: Hibernate as JPA persistence provider in WebSphere 6.1
PostPosted: Sat Jan 14, 2017 1:56 am 
Beginner
Beginner

Joined: Wed Jun 15, 2005 1:28 pm
Posts: 39
Location: United States
I tried this class, which didn't work for WebSphere Liberty 16.0.0.4, Hibernate 5.0.11 and Hibernate Search 5.5.6. I wrote a new class to solve the problem, which turned out to be much easier:

Code:
package biz.bitech.hibernate.websphere;

import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

import com.ibm.tx.jta.TransactionManagerFactory;
import com.ibm.tx.jta.UserTransactionFactory;
import org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform;

public class WebSphereJtaPlatform extends AbstractJtaPlatform {

    @Override
    protected TransactionManager locateTransactionManager() {
        return TransactionManagerFactory.getTransactionManager();
    }

    @Override
    protected UserTransaction locateUserTransaction() {
        return UserTransactionFactory.getUserTransaction();
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.