troubleshooting Question

tomcat / hibernate / jndi configuration problem

Avatar of skydancer2
skydancer2 asked on
JavaJava EE
4 Comments1 Solution6588 ViewsLast Modified:
Hi folks!
I am new to hibernate and have problems with the configuration.
tomcat 5.5.17, hibernate 3.2 and I recieve the error

org.hibernate.HibernateException: No TransactionManagerLookup specified

What could that mean?
Please help!

regards
Albert

ERROR MESSAGE
--------------------------------------------------------------------------------------------------------------------------------------------
20:38:02,296 ERROR [jsp]:253 - Servlet.service() for servlet jsp threw exception
org.hibernate.HibernateException: No TransactionManagerLookup specified
      at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:54)
      at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542)
      at cms2.user.UserDAO.list(UserDAO.java:93)
      at org.apache.jsp.listUser_jsp._jspService(listUser_jsp.java:65)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)

context.xml
--------------------------------------------------------------------------------------------------------------------------------------------
<?xml version='1.0' encoding='utf-8'?>
<Context path="caragent" debug="1" reloadable="true" crossContext="true" docBase='C:\JAVA\work\car-agent'>
   <Resource auth="Container" name="jdbc/db" scope="Shareable" type="javax.sql.DataSource"/>

  <ResourceParams name="jdbc/db">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>

    <parameter>
      <name>password</name>
      <value>password</value>
    </parameter>
    <parameter>
      <name>url</name>
      <value>jdbc:mysql://etc</value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>com.mysql.jdbc.Driver</value>
    </parameter>
    <parameter>
      <name>username</name>
      <value>username</value>
    </parameter>
  </ResourceParams>
</Context>

web.xml resource-ref entry
--------------------------------------------------------------------------------------------------------------------------------------------
            <resource-ref>
                  <description>mySQL DataSource</description>
                  <res-ref-name>jdbc/db</res-ref-name>
                  <res-type>javax.sql.DataSource</res-type>
                  <res-auth>Container</res-auth>
            </resource-ref>

hibernate.cfg.xml
--------------------------------------------------------------------------------------------------------------------------------------------
<?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">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

<session-factory>
      <property name="hibernate.connection.datasource">java:comp/env/jdbc/db</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <mapping resource="User.hbm.xml" />

</session-factory>

</hibernate-configuration>


HibernateUtil.java
--------------------------------------------------------------------------------------------------------------------------------------------
package cms2.hibernate;

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

public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
              sessionFactory = new 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;
    }
}


METHOD from the UserDAO
--------------------------------------------------------------------------------------------------------------------------------------------
    public List list(Paging paging) {
        log.debug("Userlist");
        try {
            String queryString = "from User";
            SessionFactory sf = HibernateUtil.getSessionFactory();
            Session session = sf.getCurrentSession();
            Query query = session.createQuery(queryString);
            //Query query = HibernateUtil.getSessionFactory().getCurrentSession().createQuery(queryString);
            query.setMaxResults(paging.getNumRows());
            query.setFirstResult(paging.getNumRows() * paging.getPageOffset());

            return query.list();
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }  


ASKER CERTIFIED SOLUTION
reach2piyush

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros