You can try this:


package org.hibernate.transaction;

import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

import javax.transaction.TransactionManager;

import org.apache.geronimo.gbean.AbstractName ;
import org.apache.geronimo.gbean.AbstractNameQuery;
import org.apache.geronimo.kernel.Kernel;
import org.apache.geronimo.kernel.KernelRegistry;
import org.apache.geronimo.kernel.proxy.ProxyManager;
import org.apache.geronimo.transaction.context.TransactionContextManager;
import org.hibernate.HibernateException;

public class GeronimoTransactionManagerLookup implements
        TransactionManagerLookup {

    // geronimo 1.1 object name
    public static final String TransactionMgrGBeanName = "geronimo.server:J2EEApplication=null,J2EEModule=geronimo/j2ee-server/1.1-SNAPSHOT/car,J2EEServer=geronimo,j2eeType=TransactionContextManager,name=TransactionContextManager";
    public static final String UserTransactionName = "java:comp/UserTransaction";

    public TransactionManager getTransactionManager(Properties props) throws HibernateException {
        try {
            //TODO props with geronimo kernel name
            Kernel kernel = KernelRegistry.getKernel("geronimo");
            ProxyManager proxyManager = kernel.getProxyManager();
            AbstractNameQuery query = new AbstractNameQuery( TransactionContextManager.class.getName());
            Set names = kernel.listGBeans(query);
            AbstractName name = null;
            for (Iterator it = names.iterator(); it.hasNext();)
                name = (AbstractName) it.next();
            return ((TransactionContextManager) proxyManager.createProxy(name,
                    TransactionContextManager.class)).getTransactionManager();
        } catch (Exception e) {
            e.printStackTrace();
            throw new HibernateException("Geronimo Transaction Manager Lookup Failed", e);
        }
    }

    public String getUserTransactionName() {
        return UserTransactionName;
    }
}

Remember to set this hibernate.properties

        <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect ">org.hibernate.dialect.SQLServerDialect</prop>
                    <prop key="hibernate.show_sql">false</prop>
                    <prop key="hibernate.cglib.use_reflection_optimizer ">true</prop>
                    <prop key="hibernate.transaction.flush_before_completion">true</prop>
                    <prop key="hibernate.transaction.auto_close_session ">true</prop>
   
                       <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>               
                    <prop key=" hibernate.transaction.manager_lookup_class">org.hibernate.transaction.GeronimoTransactionManagerLookup</prop>
                     <prop key="hibernate.current_session_context_class">thread</prop>
                    <!-- <prop key="hibernate.current_session_context_class">jta</prop>-->
                    <prop key="jta.UserTransaction">java:comp/UserTransaction</prop>
                   
                    <prop key="hibernate.cache.use_query_cache">true</prop>
                    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider </prop>
                    <prop key="hibernate.cache.provider_configuration_file_resource_path">src/main/resources/ehcache-hibernate3.xml</prop>               
                </props>
        </property>


On 11/8/06, Peter <peter.empen@dak.de> wrote:
A suggested solution for Geronimo 1.0 is available at
http://cwiki.apache.org/confluence/display/GMOxDOC10/JBoss+to+Geronimo+-
+Hibernate+Migration. Unfortunately this does not work for Geronimo 1.1.

What I have tried is:
public class GeronimoTransactionManagerLookup
    implements TransactionManagerLookup
{
   public static final String TransactionMgrGBeanName=
                        " geronimo.server:J2EEApplication=null," +
                        "J2EEModule=geronimo/j2ee-server/1.1.1/car," +
                        "J2EEServer=geronimo,j2eeType=TransactionManager," +
                        "name=TransactionManager";
   ...

but I still get

DEBUG [SessionFactoryObjectFactory] initializing class
SessionFactoryObjectFactory
DEBUG [SessionFactoryObjectFactory] registered:
8b81890a0ec727bb010ec727c8de0000 (unnamed)
INFO  [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name
configured
DEBUG [SessionFactoryImpl] instantiated session factory
DEBUG [SessionFactoryImpl] obtaining JTA TransactionManager
ERROR [PersistenceManager] Geronimo Transaction Manager Lookup Failed
org.hibernate.HibernateException: Geronimo Transaction Manager Lookup Failed
        at
org.hibernate.transaction.GeronimoTransactionManagerLookup.getTransactionManage
r(GeronimoTransactionManagerLookup.java:29)
        at org.hibernate.impl.SessionFactoryImpl.<init>
(SessionFactoryImpl.java:301)
        at org.hibernate.cfg.Configuration.buildSessionFactory
(Configuration.java :1154)

How should this GBeanName be set? Or do I need to change something else?