Maybe I 'm still miss some point, but I think that's what do the org.apache.geronimo.transaction.context.GeronimoTransactionManager [1] of the jencks project. I was in need for it in ServiceMix, because when using xa transactions, the JBI container has to suspend / resume transactions. This is due to the fact the JBI components pull messages from a queue in their own threads, but the transaction is conveyed on the JBI message exchange. Therefore, ServiceMix suspends the current transaction when the message is queued, and resume it when it is dequeued
(in another thread).
The problem is that the only standard way to suspend / resume transactions is to use the TransactionManager, but the geronimo implementation does not work well when working on UserTransaction : all resources enlisted in the user transaction are managed by the TransactionContextManager and if you call the TransactionManager directly, the TransactionContextManager is bypassed.

The GeronimoTransactionManager (in jencks project) wraps the TransactionContextManager and implements both UserTransaction and TransactionManager. In addition, it allows the use of unmanaged threads by creating an empty context for the thread where the transaction is started / resumed, if none exists already. This implementation can easily be used by the existing spring JtaTransactionManager.
The gbeans written for ServiceMix do use this implementation.

Cheers,
Guillaume Nodet

[1] http://cvs.codehaus.org/viewrep/jencks/jencks/src/main/java/org/apache/geronimo/transaction/context

David Jencks wrote:

This looks like it should work. I think there is some chance that it would work even better if we provided a transaction manager that wraps our transactioncontextmanager, but it's too early in the morning for me to think straight about it. If you get into problem with connections not being returned to the pool let me know and I will think about it harder. How do you provide access to the jdbc connection? By declaring a resource-ref in the j2ee component that is calling hibernate, or some other way?

thanks
david jencks

On Feb 3, 2006, at 12:42 AM, Jason Dillon wrote:

It looks like you can be the first to test out my new SpringTransactionManager :-). It wraps our TransactionContextManager in a PlatformTransactionManager subclass. You need to give it 2 constructor args, the kernel name and the tcm object name. The normal values are in the comments in the class.


Aight... kick it down yo.


What does Hibernate need? Can it work off a spring tm or does it need something else?


I think it wants a special lookup class... I wrote one up tonight based on comments to the dev list a while ago... creating a proxy to the TransactionManager instance. I have yet to test it though.


If you can come up with some kind of spring app that ought to work and uses the spring tm I would be able to test and perhaps debug my code :-)


I might be able to come up with something simple... though right now first priority is to just get something... anything working inside of Geronimo so our SE dept. can test it.

Anyways, looks like spring needs a Geronimo version like:

http://www.springframework.org/docs/api/org/springframework/ transaction/jta/WebSphereTransactionManagerFactoryBean.html

I've yet to look at what this puppy does.

And Hibernate needs a Geronimo version of:

http://cvs.sourceforge.net/viewcvs.py/hibernate/Hibernate3/src/org/ hibernate/transaction/JOTMTransactionManagerLookup.java? rev=1.1&view=auto

This is what I wrote and will be testing out tomorrow.

<snip>
package com.solidusnetworks.utils.geronimo;

import java.util.Properties;

import javax.transaction.TransactionManager;
import javax.management.ObjectName;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.transaction.TransactionManagerLookup;

import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.KernelRegistry;

/**
* Provides lookup of the Geronimo (1.0) transaction manager.
*
* @version $Id$ $Date$
* @author <a href="mailto:[EMAIL PROTECTED]">Jason  Dillon</a>
*/
public class GeronimoTransactionManagerLookup
    implements TransactionManagerLookup
{
public static final String TXM_GBEAN_NAME = "geronimo.server:J2EEApplication=null,J2EEModule=geronimo/j2ee- server/1.0/ car,J2EEServer=geronimo,j2eeType=TransactionManager,name=TransactionMa nager"; public static final String USER_TXN_NAME = "java:comp/ UserTransaction";

public TransactionManager getTransactionManager(final Properties props) throws HibernateException {
        try {
            //
// FIXME: This is probably not work when Geronimo versions change... :-(
            //
            ObjectName TM_NAME = new ObjectName(TXM_GBEAN_NAME);
            Kernel kernel = KernelRegistry.getSingleKernel();
return (TransactionManager) kernel.getProxyManager ().createProxy(TM_NAME, TransactionManager.class);
        }
        catch (Exception e) {
throw new HibernateException("Failed to lookup Geronimo transaction manager", e);
        }
    }

    public String getUserTransactionName() {
        return USER_TXN_NAME;
    }
}
</snip>

--jason





Reply via email to