-->
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.  [ 2 posts ] 
Author Message
 Post subject: Interceptor->afterTransactionCompletion not invoked with JTA
PostPosted: Fri Apr 13, 2012 10:31 pm 
Beginner
Beginner

Joined: Fri Jan 29, 2010 8:17 pm
Posts: 20
Location: Portland OR
I just upgraded from Hibernate 3.5 to 4.1.2. I'm using Atomikos 3.7 as the JTA provider. I implemented JtaPlatform by extending AbstractJtaPlatform(which was not obvious from the docs nor migration guide that I needed to do this). Everything seems to be mostly working OK except for my Intercepter implementation that isn't having 'afterTransactionCompletion' invoked on it. Not having it invoked is leaving some thread local data that is normally cleaned up in 'afterTransactionCompletion' around. But beforeTransactionCompletion, onSave, etc are being invoked. I debugged a little bit and I see the problem/inconsistency. The other methods don't check if 'TransactionImplementor hibernateTransaction' is null, and just invoke the interceptor. What is bothering me is that 3.5.x essentially does the same thing(the tx != null check for the after invocation), but that release worked fine for me. For some reason the transaction synchronizations appear to be working but there isn't an associated Hibernate transaction to go with the JTA transaction. Other than that data gets persisted just fine, but not being able to clean up my interceptors state post transactions is a problem.

Here is what my 3.5.x transaction manager lookup and factory combo essentially looked like:

Code:
public class AtomikosTransactionManagerLookup implements org.hibernate.transaction.TransactionManagerLookup {
    private UserTransactionManager utm;
    public AtomikosTransactionManagerLookup() {
        utm = new UserTransactionManager();
    }
    @Override
    public TransactionManager getTransactionManager(Properties props) throws HibernateException {
        return utm;
    }
    @Override
    public String getUserTransactionName() {
        return null;
    }
    @Override
    public Object getTransactionIdentifier(Transaction transaction) {
        return transaction;
    }
}

public class AtomikosJTATransactionFactory extends JTATransactionFactory {
    private UserTransaction userTransaction;
    @Override
    public void configure ( Properties props ) throws HibernateException {
        try {
               super.configure ( props );
        } catch ( Exception e ) {
             String msg = "Hibernate: error during config - ignore for hibernate 3.2.7 or higher";
             Configuration.logDebug ( msg , e );
        }
    }
    @Override
    protected UserTransaction getUserTransaction() {
        if (this.userTransaction == null) {
            this.userTransaction = new UserTransactionImp();
        }
        return this.userTransaction;
    }
}


And here is my 4.x Atomikos JTA platform. I just plugin the field values from externally configured userTransaction and manager(yes I'm in major hack mode right now).
Code:
public class AtomikosJtaPlatform extends AbstractJtaPlatform {

   public static UserTransaction userTransaction;
   public static UserTransactionManager userTransactionManager;

   @Override
   protected TransactionManager locateTransactionManager() {
      return userTransactionManager;
   }

   @Override
   protected UserTransaction locateUserTransaction() {
      return userTransaction;
   }

}


I'm configuring using the javax.persistence.Persist API since Ejb3Configuration is now deprecated(what I was using in 3.5.x):
Code:
overrides.put("hibernate.ejb.interceptor", MyInterceptor.class.getName());
overrides.put( AvailableSettings.JTA_PLATFORM, AtomikosJtaPlatform.class.getName() );
overrides.put( AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "jta");
overrides.put( AvailableSettings.RELEASE_CONNECTIONS, "after_statement");
overrides.put("hibernate.connection.datasource", datasourceName);
//tried only setting jtaDataSource, but that seemed to be problematic
overrides.put("javax.persistence.jtaDataSource", datasourceName);
… lots of other unrelated settings
EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu", overrides);


I don't know if its correct that there isn't a hibernate transaction('TransactionImplementor hibernateTransaction') or not in 4.x when I'm using JTA. If it isn't correct I'm wondering what I'm doing wrong that is preventing the associated Hibernate Transaction from being created to be paired with the JTATransaction.

Anything obvious here? Would be great if a core developer can chime in on whether or not something is obviously wrong here or if someone whom has gotten Atomikos to work with 4.x could chime in with an example.

Thanks,
ZK


Top
 Profile  
 
 Post subject: Re: Interceptor->afterTransactionCompletion not invoked with JTA
PostPosted: Sun Apr 15, 2012 5:37 pm 
Beginner
Beginner

Joined: Fri Jan 29, 2010 8:17 pm
Posts: 20
Location: Portland OR
Looks like my assumptions about the interceptor API were a bit off after looking around the source a bit more. Apparently it is only if the hibernate transaction API is being used that the interceptor's various methods are going guaranteed to be called. Some happen to be called(onSave, beforeTransactionCommit), while others (afterTransactionBegins, afterTransactionCompletes) aren't called when using pure JTA.

During my attempts to get the pure JTA approach to work I had disabled some wrapping code in my app that created/committed a hibernate transaction crud operations. I've re-enabled that and the interceptor is getting the invocations it needs. However, now I'm getting lots of transaction not in progress errors during some of my tests:
Code:
org.hibernate.HibernateException: Current transaction is not in progress
   at org.hibernate.context.internal.JTASessionContext.currentSession(JTASessionContext.java:94)


Either something is wrong with my JtaPlatform integration, or the upgrade has exposed a bug in some application code. In any case, this post is now basically based off of an invalid assumption. I'll take some time to understand more of whats going on under the covers and post an Atomikos and Hibernate 4.x recipe once I get it figured.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.