-->
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.  [ 2 posts ] 
Author Message
 Post subject: data resources in tomcat server.xml
PostPosted: Mon Mar 29, 2004 3:07 am 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
using hibernate 2.0.2, tomcat 4.1.12, mysql 4.0.17

i use to have only this context configured in my tomcat server.xml file:
Code:
<Context path="/cemiterio" docBase="C:\Otavio_Augusto\transporte\projetos\cemiterios\projeto\build\cemiterio" debug="0" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
                     prefix="localhost_examples_log." suffix=".txt"
             timestamp="true"/>
<Resource name="jdbc/cemiterio" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/cemiterio">
<parameter><name>factory</name><value>org.apache.commons.dbcp.BasicDataSourceFactory</value></parameter>

<parameter><name>url</name><value>jdbc:mysql://localhost/cemiterio</value></parameter>

<parameter><name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value></parameter>

<parameter><name>username</name><value>user</value></parameter>

<parameter><name>password</name><value>secret</value></parameter>

<parameter><name>maxWait</name><value>5000</value></parameter>

<parameter><name>maxIdle</name><value>2</value></parameter>

<parameter><name>maxActive</name><value>5</value></parameter>
</ResourceParams>
</Context>


ok, it was fine. but now i'm developing another application, and i suppose i have to add similar lines to it, right? a new context to server.xml ...
i understand the lines above configure a data source for a connection pool. is it possible to have another connection pool for another data source? this is the new context i'm trying to add to server.xml
Code:
<Context path="/plano" docBase="C:\Otavio_Augusto\projetos\plano\projeto\build\plano"
debug="0" reloadable="true" crossContext="true">

<Logger className="org.apache.catalina.logger.FileLogger"
                     prefix="localhost_examples_log." suffix=".txt"
             timestamp="true"/>
<Resource name="jdbc/plano" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/plano">
<parameter><name>factory</name><value>org.apache.commons.dbcp.BasicDataSourceFactory</value></parameter>

<parameter><name>url</name><value>jdbc:mysql://localhost/plano</value></parameter>

<parameter><name>driverClassName</name><value>org.gjt.mm.mysql.Driver</value></parameter>

<parameter><name>username</name><value>user</value></parameter>

<parameter><name>password</name><value>pass</value></parameter>

<parameter><name>maxWait</name><value>5000</value></parameter>

<parameter><name>maxIdle</name><value>2</value></parameter>

<parameter><name>maxActive</name><value>5</value></parameter>
</ResourceParams>
</Context>


i get the following error in tomcat's log:
Code:
2004-03-29 03:38:27 WebappLoader[/plano]: Reloading checks are enabled for this Context
2004-03-29 03:38:28 StandardManager[/plano]: Seeding random number generator class java.security.SecureRandom
2004-03-29 03:38:28 StandardManager[/plano]: Seeding of random number generator has been completed
2004-03-29 03:38:29 StandardContext[/plano]: Exception sending context initialized event to listener instance of class struts.PlanoContextListener
java.lang.NoClassDefFoundError
   at struts.PlanoContextListener.contextInitialized(Unknown Source)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3250)

let me explain: in PlanoContextListener, i try to get a connection from the pool (teh same way i do in the other application i mentioned...nothing weird) inside the contextInitialized method. i have a singleton class that does it for me, called HibernateUtil. so, i just do

Code:
Session session = HibernateUtil.currentSession();

and at this point the app crashes, and only the other contexts keep working.

this is the HibernateUtil class i mentioned:

Code:
public class HibernateUtil {
   
   private static final SessionFactory sessionFactory;

      static {
         try {
            sessionFactory = new Configuration().configure().buildSessionFactory();
         } catch (HibernateException ex) {
            throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
         }
      }

      public static final ThreadLocal session = new ThreadLocal();

      public static Session currentSession() throws HibernateException {
         Session s = (Session) session.get();
         // Open a new Session, if this Thread has none yet
         if (s == null) {
            s = sessionFactory.openSession();
            session.set(s);
         }
         return s;
      }

      public static void closeSession() throws HibernateException {
         Session s = (Session) session.get();
         session.set(null);
         if (s != null)
            s.close();
      }


}

Any help?
thanks for reading this.

_________________
Ot


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 29, 2004 7:13 pm 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
in addition to the last message, i found out that my app is trying to connect to the database. if i put a wrong user name or password in the context configuration of the server.xml file , i get a sqlexception. so.... using the correct password and username, i actually connect to the database. so, the problem seems to be the session: it is not being created.

thanks a lot.

_________________
Ot


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

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.