geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michele La Porta" <michele.lapo...@gmail.com>
Subject Re: Geronimo 1.1 with Hibernate 3.1
Date Mon, 08 Jan 2007 08:50:48 GMT
If you use geronimo-1.1.x you also need to bind transaction manager in jndi.
I use xbean to define a InitialContext like:

        <!-- JNDI configuration -->
        <bean id="jndi" class="
org.apache.xbean.spring.jndi.SpringInitialContextFactory"
                factory-method="makeInitialContext" singleton="true">
                <description>A simple JNDI initial context.</description>
                <property name="entries">
                        <map>
                            <entry key="java:comp/UserTransaction"
value-ref="userTransaction" />
                        </map>
                </property>
        </bean>

        <bean id="userTransaction" class="
org.jencks.factory.TransactionManagerFactoryBean"/>

        <bean id="transactionManager" class="
org.springframework.transaction.jta.JtaTransactionManager">
            <property name="userTransaction" ref="userTransaction" />
            <property name="userTransactionName"
value="java:comp/UserTransaction"/>
        </bean>

    <!-- Hibernate SessionFactory -->
    <bean id="hibernate3SessionFactory" class="
org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="lobHandler" ref="lobHandler"/>
        <property name="dataSource" ref="dataSource"/>
        <property name="jtaTransactionManager" ref="userTransaction"/>
        <property name="mappingResources">
            <list>
                <value>Payphone.hbm.xml</value>
        <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">${
com.urmet.rd.g200.resources.dir}/ehcache-hibernate3.xml</prop>

                    <prop key="hibernate.jdbc.batch_size">50</prop>
                    <prop key="hibernate.cache.use_second_level_cache
">false</prop>
                    <prop key="hibernate.max_fetch_depth">2</prop>
                    <prop key="hibernate.default_batch_fetch_size">8</prop>

                </props>
        </property>
    </bean>

And jndi.properties with :
java.naming.factory.initial =
org.apache.xbean.spring.jndi.SpringInitialContextFactory
java.naming.provider.url = file:${resources.dir}/applicationContext-
setup.xml

I use this dependency :

        <!-- jndi support -->
        <dependency>
            <groupId>org.apache.xbean</groupId>
            <artifactId>xbean-spring</artifactId>
            <version>2.7</version>
        </dependency>

        <!-- hibernate3 support -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>2.1_3</version>
        </dependency>

        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm-commons</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm-util</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm-attrs</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.1.3.1</version><!-- patch version confict with
activemq properties  -->
            <exclusions>
                <exclusion>
                    <artifactId>cglib</artifactId>
                    <groupId>cglib</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>asm</artifactId>
                    <groupId>asm</groupId>
                </exclusion>
            </exclusions>
        </dependency>

         <dependency>
            <groupId>org.jencks</groupId>
            <artifactId>jencks</artifactId>
            <!-- <version>1.3</version> -->
            <version>2.0-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.geronimo.modules</groupId>
                    <artifactId>geronimo-core</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-common</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-connector</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-deployment</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-j2ee</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-kernel</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-naming</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-security</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-system</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-transaction</artifactId>
                </exclusion>
                <exclusion>
                     <groupId>org.apache.geronimo.modules</groupId>
                     <artifactId>geronimo-util</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.geronimo.modules</groupId>
            <artifactId>geronimo-transaction</artifactId>
            <version>${geronimo.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.modules</groupId>
            <artifactId>geronimo-connector</artifactId>
            <version>${geronimo.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.modules</groupId>
            <artifactId>geronimo-system</artifactId>
            <version>${geronimo.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.geronimo.modules</groupId>
            <artifactId>geronimo-core</artifactId>
            <version>${geronimo.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-j2ee_1.4_spec</artifactId>
            <version>1.1</version>
        </dependency>


If you use geronimo-2.x the jndi tree should be available..




2007/1/5, jwan@21technologies.com <jwan@21technologies.com>:
>
>
> Peter,
>    did you end up trying this? Did it work for you? I will need to use
> something similar very soon.
>
> *--
> Jimmy Wan
> Senior Technical Lead
> 21st Century Technologies, Inc.
> URL: http://www.21technologies.com*
>
> *The information in this email and in any attachments is confidential and
> may be privileged. If you are not the intended recipient, please destroy
> this message, delete any copies held on your systems and notify the sender
> immediately. You should not retain, copy or use this email for any purpose,
> nor disclose all or any part of its content to any other person.*
>
>
>  *"Michele La Porta" <michele.laporta@gmail.com>*
>
> 11/08/2006 07:16  Please respond to
> user@geronimo.apache.org
>
>   To
> user@geronimo.apache.org  cc
>
>  Subject
> Re: Geronimo 1.1 with Hibernate 3.1
>
>
>
>
>
>
> 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* <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+-
> *<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?
>
>

Mime
View raw message