-->
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.  [ 7 posts ] 
Author Message
 Post subject: Problem running simple servlet with Hibernate. Please help!
PostPosted: Thu Jul 26, 2007 3:34 am 
Newbie

Joined: Mon Jul 23, 2007 10:17 am
Posts: 12
Location: www.ultrasharpware.com
Hi!
I'm trying to write simplest servlet with hibernate. But I can't execute it.
I receive java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
I think i have problem with my hibernate.cfg.xml.

My tomcat folder looks like this:
+ web-inf
web.xml

+ classes
+ hibernate - package
Servlet.class
Client.class
hibernate.cfg.xml
Client.hbm.xml

hibernate3.jar and other jars are in the /lib folder so I think it's not the point. Please help!!!!


Source:

Code:
package hibernate;


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;


import org.hibernate.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;


public class Servlet extends HttpServlet {
        private static final String CONTENT_TYPE = "text/html; charset=windows-1251";

      //Initialize global variables
        public void init() throws ServletException {
        }


        public void store(Client c, PrintWriter pr){

                 // configutating Hibernate
                SessionFactory sf = null;
                Configuration cfg = new Configuration().configure();
                pr.println("<br>Hibernate configurated...");

                try {
                        sf = cfg.buildSessionFactory();//new Configuration().configure().buildSessionFactory();
                        pr.println("<br>SessionFactory received...");
                } catch (HibernateException e) {
                        pr.println("<br><font color=red>Error</font>: SessionFactory creation failed " + e.getMessage() + "! ");
                }

                // Opening session
                Session session = sf.openSession();
                pr.println("<br>Session opened...");

                // Saving object
                Transaction t = session.beginTransaction();
                session.save( c );
                t.commit();
                pr.println("<br>Object saved...");

                // Closing session
                session.close();
                pr.println("<br>Session closed...");

        }


      //Process the HTTP Get request
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                response.setContentType(CONTENT_TYPE);
                PrintWriter out = response.getWriter();
                out.println("<html>");
                out.println("<head><title>Servlet1</title></head>");
                out.println("<body>");
                out.println("<p>The servlet has received a GET. This is the reply.</p>");

                Client cl = new Client("Stas", "8-097-933-48-42", "Ukraine");
                out.println("<br>Trying to store client...<br><br>");
                store(cl, out);

                out.println("</body></html>");

      }


      //Clean up resources
        public void destroy() {
        }
}


Code:
<?xml version='1.0'?>
<!DOCTYPE hibernate-configuration>

<hibernate-configuration>

    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/hibernate</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>


        <mapping resource="Client.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

[/code]

_________________
kodlan
http://www.UltraSharpWare.com
http://www.UltraSharpWare.com/blog


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 6:51 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

change your code and test this.


public void store(Client c, PrintWriter pr){

// configutating Hibernate
SessionFactory sf = null;
Configuration cfg = new Configuration();
confg.setProperty("hibernate.connection.driver_class","org.gjt.mm.mysql.Driver");
confg.setProperty("hibernate.connection.url","jdbc:mysql://localhost/hibernate");
confg.setProperty("hibernate.connection.username","root");
confg.setProperty("hibernate.connection.password","" );
confg.setProperty("hibernate.dialect","org.hibernate.dialect.MySQLDialect");
confg.setProperty("hibernate.connection.pool_size","10");
confg.setProperty("hibernate.cache.provider_class","org.hibernate.cache.NoCacheProvider");
confg.setProperty("hibernate.current_session_context_class","thread");
confg.setProperty("hibernate.jdbc.use_scrollable_resultset","true");
confg.setProperty("hibernate.show_sql","true");

pr.println("<br>Hibernate configurated...");

try {
sf = cfg.buildSessionFactory();//new Configuration().configure().buildSessionFactory();
pr.println("<br>SessionFactory received...");
} catch (HibernateException e) {
pr.println("<br><font color=red>Error</font>: SessionFactory creation failed " + e.getMessage() + "! ");
}

// Opening session
Session session = sf.openSession();
pr.println("<br>Session opened...");

// Saving object
Transaction t = session.beginTransaction();
session.save( c );
t.commit();
pr.println("<br>Object saved...");

// Closing session
session.close();
pr.println("<br>Session closed...");

}

changed
added

Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 7:26 am 
Newbie

Joined: Mon Jul 23, 2007 10:17 am
Posts: 12
Location: www.ultrasharpware.com
amila733 wrote:
Hi
change your code and test this.


I was running everything in JBuilder (well the only Internet access I currently have is thru GPRS, and I'll download j2ee later, thats why I've used jbuilder). After I've moved everything into Tomcat my original code returned org.hibernate.MappingException. I've changed it as you've said and it passed configuration. When commenting everething below configuration - it's ok. I receive folowing exceptions if I leave the rest of the code.

PS: Which driver is correct for MySQL com.mysql.jdbc.Driver or org.gjt.mm.mysql.Driver?

[code]javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Thread.java:534)

root cause
java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:57)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:414)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at hibernate.Servlet.store(Servlet.java:47)
at hibernate.Servlet.doGet(Servlet.java:81)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Thread.java:534)[code]


Quote:
(Don't forget to rate if helps)

Okay!

_________________
kodlan
http://www.UltraSharpWare.com
http://www.UltraSharpWare.com/blog


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 7:30 am 
Newbie

Joined: Mon Jul 23, 2007 10:17 am
Posts: 12
Location: www.ultrasharpware.com
PS: tomcat wrote in console :

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.

_________________
kodlan
http://www.UltraSharpWare.com
http://www.UltraSharpWare.com/blog


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 7:58 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

use this mysql-connector-java-3.1.10-bin.jar


Amila
(Dont' forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 8:04 am 
Newbie

Joined: Mon Jul 23, 2007 10:17 am
Posts: 12
Location: www.ultrasharpware.com
amila733 wrote:
Hi

use this mysql-connector-java-3.1.10-bin.jar

well, I'm using mysql-connector-java-5.0.7-bin.jar.
I've asked about the name which should be used in hibernate.cfg.xml.

Any thoughts why do I receive org.hibernate.MappingException exception?

_________________
kodlan
http://www.UltraSharpWare.com
http://www.UltraSharpWare.com/blog


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 12:30 pm 
Newbie

Joined: Mon Jul 23, 2007 10:17 am
Posts: 12
Location: www.ultrasharpware.com
The problem was the wrong hibernate.cfg.xml and Client.hbm.xml.
Everything is ok now.

_________________
kodlan
http://www.UltraSharpWare.com
http://www.UltraSharpWare.com/blog


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