-->
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.  [ 1 post ] 
Author Message
 Post subject: Tomcat, JOTM - Could not register synchronization
PostPosted: Tue Aug 15, 2006 12:22 pm 
Newbie

Joined: Tue Aug 15, 2006 4:56 am
Posts: 1
Location: London, United Kingdom
Hello all,

I've been trying to set up Tomcat 5.5.17 and Hibernate 3.1.3 to use transactions using JOTM (http://jotm.objectweb.org/). I used JOTM because it's been recommended for Tomcat and I have several existing clients who wouldn't want to upgrade their application server.

I'm having some real troubles, I managed to get JOTM transaction to function with Tomcat 5.5.17 following the simple instructions from http://static.raibledesigns.com/downloa ... -jotm.html. I used the dbtest.war file linked from the bottom of the howto page, it worked really well I could do a JNDI lookup for UserTransaction and it would receive an object.

Once I added hibernate and my application, then ran the application calling the Transaction using HibernateUtil.getSessionFactory().getCurrentSession(); it would spit out the following exception:

Code:
[b]
org.hibernate.TransactionException: could not register synchronization
   org.hibernate.transaction.JTATransaction.registerSynchronization(JTATransaction.java:309)
   org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:78)
   org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:508)
   com.lloydnorthover.me.dao.hibernate.HibernateDAOFactory.getCurrentSession(HibernateDAOFactory.java:21)
   com.lloydnorthover.me.dao.hibernate.HibernateDAOFactory.getPageDAO(HibernateDAOFactory.java:12)
   org.apache.jsp.system.editor.dir_005fselect_005flist_jsp._jspService(dir_005fselect_005flist_jsp.java:87)
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
[/b]


I'm really stuck and can't see a light at the end of the tunnel. I've looked all over the web for a solution but I haven't found anything. Could someone put me in the right direction?

Thank you.

Code:
[b]
<Context reloadable="true">

    <Resource name="jdbc/mediaengineDB" auth="Container" type="javax.sql.DataSource"
        factory="org.objectweb.jndi.DataSourceFactory"
        driverClassName="com.mysql.jdbc.Driver"
        username="mediaengine_user" password="mediaengine999" url="jdbc:mysql://localhost:3306/mediaengineHibernate?autoReconnect=true"/>
       
    <Transaction name="UserTransaction" auth="Application"
    type="javax.transaction.UserTransaction"
    factory="org.objectweb.jotm.UserTransactionFactory"
    jotm.timeout="60"/>


</Context>



<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.datasource">java:comp/env/jdbc/mediaengineDB</property>
      
        <!-- <property name="connection.url">jdbc:mysql://localhost:3306/mediaengineHibernate?autoReconnect=true</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.username">user</property>
        <property name="connection.password">pass</property> -->
      
        <!-- JDBC connection pool (use the built-in) -->
        <!--
        <property name="connection.pool_size">10</property>
      -->
      <!-- Enable Hibernate's automatic session context management -->
      
        <property name="jta.UserTransaction">java:comp/UserTransaction</property>
        <property name="transaction.manager_lookup_class">org.hibernate.transaction.JOTMTransactionManagerLookup</property>
      <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
      
      <!-- Using open source C3PO production level JDBC database connection pooling instead of default hibernate -->
        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">50</property>
        <property name="hibernate.c3p0.timeout">1800</property>
        <property name="hibernate.c3p0.max_statements">50</property>
      
        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
        <property name="dialect">org.hibernate.dialect.MySQLMyISAMDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <!-- <property name="hbm2ddl.auto">create</property> -->

        <mapping resource="com/lloydnorthover/me/model/Template.hbm.xml"/>

    </session-factory>

</hibernate-configuration>



package com.persistance;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

    private static Configuration configuration;
    private static SessionFactory sessionFactory;
   
    static {
        try {
         configuration = new Configuration();
            // Create the SessionFactory from hibernate.cfg.xml
            sessionFactory = configuration.configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    /**
     * Returns the original Hibernate configuration.
     *
     * @return Configuration
     */
    public static Configuration getConfiguration() {
        return configuration;
    }

}



package com.dao.hibernate;

import com.lloydnorthover.me.dao.*;
import org.hibernate.Session;
import com.lloydnorthover.me.persistance.HibernateUtil;

public class HibernateDAOFactory extends DAOFactory
{
   
    public PageDAO getPageDAO() {
        return new PageDAOHibernate(getCurrentSession());
    }

    public TemplateDAO getTemplateDAO() {
        return new TemplateDAOHibernate(getCurrentSession());
    }
   
    // You could override this if you don't want HibernateUtil for lookup
    protected Session getCurrentSession() {
        return HibernateUtil.getSessionFactory().openSession();
    }
}
[/b]


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

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.