-->
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.  [ 3 posts ] 
Author Message
 Post subject: question : hibernate3.0.5+ tomcat5.5.12
PostPosted: Thu Nov 10, 2005 7:33 am 
Newbie

Joined: Wed Nov 02, 2005 3:42 am
Posts: 5
I create the webapps according to the reference of hibernate of version 3.0.5.
In tomcat webapps i create the directory of quickstart who is just like this:
+src
+org
+hibernate
+examples
+quickstart
-Cat.java
-HibernateUtil.java
-TestHServlet.java (a servlet )
+WEB-INF
+classes
+org
-Cat.hbm.xml
-hibernate.cfg.xml
-log4j.properties
+hibernate
+examples
+quickstart
-Cat.class
-HibernateUtil.class
-TestHServlet.class
+lib
-web.xml
in tomcat ,under the directory of conf\server.xml ,i added the Context describing the JNDI
<Context path="/quickstart" docBase="quickstart">
<Resource name="jdbc/quickstart" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/quickstart">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/quickstart</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>username</name>
<name>root</name>
</parameter>
<parameter>
<name>password</name>
<value>dfjk</value>
</parameter>
<!--DBCP connection pooling options-->
<parameter>
<name>maxWait</name>
<value>3000</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>100</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
</ResourceParams>
</Context>


the context of web.xml is


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xdd"
version="2.4">
<display-name>Hibernate connect the DB with Tomcat </display-name>
<description>
Persistence layer using Hibernate
</description>

<servlet>
<servlet-name>TestHServlet</servlet-name>
<servlet-class>org.hibernate.examples.quickstart.TestHServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestHServlet</servlet-name>
<url-pattern>/HibernateQuickstart</url-pattern>
</servlet-mapping>
<resource-ref>
<description>DB connection</description>
<res-ref-name>jdbc/quickstart</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>


the main content of hibernat.cfg.xml is


<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/quickstart</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="Cat.hbm.xml"/>
</session-factory>
</hibernate-configuration>

the configuration the Cat.hbm.xml is

<hibernate-mapping>
<class name="org.hibernate.examples.quickstart.Cat" table="CAT">
<id name="id" type="string" unsaved-value="null">
<column name="CAT_ID" not-null="true"/>
<generator class="generator"/>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="name">
<column name="NAME" length="16" not-null="true"/>
</property>
<property name="sex"/>
<property name="weight"/>
</class>
</hibernate-mapping>



when i keypress http://localhost:8080/quickstart/HibernateQuickstart ,there errors generated as following:

exception

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.ExceptionInInitializerError
org.hibernate.examples.quickstart.HibernateUtil.<clinit>(HibernateUtil.java:18)
org.hibernate.examples.quickstart.TestHServlet.doGet(TestHServlet.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

How to deal with it ,3X
gabendou


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 10, 2005 9:55 am 
Beginner
Beginner

Joined: Fri Oct 28, 2005 10:46 am
Posts: 37
Cat.hbm.xml, hibernate.cfg.xml, and log4j.properties should be in the root of your classpath (WEB-INF/classes), not in the org package.

A less important issue is that you should not put Contexts in the server.xml. Create an independent context file in your host's conf directory ($CATALINA_HOME/conf/Catalina/localhost by default). Learn more about configuring contexts here:
http://tomcat.apache.org/tomcat-5.5-doc ... ntext.html


Top
 Profile  
 
 Post subject: thanks
PostPosted: Wed Nov 16, 2005 1:47 am 
Newbie

Joined: Wed Nov 02, 2005 3:42 am
Posts: 5
thank you !!


zzantozz wrote:
Cat.hbm.xml, hibernate.cfg.xml, and log4j.properties should be in the root of your classpath (WEB-INF/classes), not in the org package.

A less important issue is that you should not put Contexts in the server.xml. Create an independent context file in your host's conf directory ($CATALINA_HOME/conf/Catalina/localhost by default). Learn more about configuring contexts here:
http://tomcat.apache.org/tomcat-5.5-doc ... ntext.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.