Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / August 2004

Tip: Looking for answers? Try searching our database.

PLEASE HELP! Tomcat and Hibernate  ServletException, net/sf/cglib/core/KeyFactory problem

Thread view: 
Tung Chau - 20 Aug 2004 05:19 GMT
Hi,
I am newbie to Hibernate. I followed the instructions on the following
page to configure Tomcat to work with Hibernate.
http://www.hibernate.org/hib_docs/reference/en/html/quickstart.html
I tested hibernate with a simple Employee table and Employee.hbm.xml
===================================================================
My /src directory has
hibernate.cfg.xml at the root.
HibernateUtil.java inside package proj.db.
Employee.java inside package proj.mapping.
Employee.hbm.xml inside package proj.mapping.
==================================================================
The following code is put in test.jsp to test hibernate
"try{
Session s = HibernateUtil.currentSession();

Transaction tx= s.beginTransaction();

Employee E = new Employee();
E.setFirstName("blue");
E.setLastName("blue");
E.setEmail("blue@gmail.com");

s.save(E);
tx.commit();

HibernateUtil.closeSession();
}catch (Exception e) {
 out.println(e.getMessage());
}"
================================================
package proj.db;

import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;

public class HibernateUtil {

   //private static Log log = LogFactory.getLog(HibernateUtil.class);

   private static final SessionFactory sessionFactory;

   static {
       try {
           // Create the SessionFactory
           Configuration conf= new Configuration()
           .addClass(elearning.mapping.Employee.class);
           //sessionFactory = new
Configuration().configure().buildSessionFactory();
           sessionFactory = conf.buildSessionFactory();
       } catch (Throwable ex) {
           System.out.println("HUHUHU");
            System.out.println("******" + ex.getMessage());
           //log.error("Initial SessionFactory creation failed.",
ex);
           throw new ExceptionInInitializerError(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();
   }
}
================================================================
========================================================
I got the following Servlet Exception
type Exception report

message

description The server encountered an internal error () that prevented
it from fulfilling this request.

exception

org.apache.jasper.JasperException
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

............
root cause

javax.servlet.ServletException
    at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536)
    at org.apache.jsp.test_jsp._jspService(test_jsp.java:106)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

=======================================================
Here is part of the output in catalina.out:
"Aug 19, 2004 8:43:16 PM
net.sf.hibernate.transaction.TransactionManagerLookupFactory
getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use
of process level read-write cache is not recommended)
Aug 19, 2004 8:43:16 PM net.sf.hibernate.cfg.SettingsFactory
buildSettings
INFO: Use scrollable result sets: true
Aug 19, 2004 8:43:16 PM net.sf.hibernate.cfg.SettingsFactory
buildSettings
INFO: Use JDBC3 getGeneratedKeys(): false
Aug 19, 2004 8:43:16 PM net.sf.hibernate.cfg.SettingsFactory
buildSettings
INFO: Optimize cache for minimal puts: false
Aug 19, 2004 8:43:16 PM net.sf.hibernate.cfg.SettingsFactory
buildSettings
INFO: Query language substitutions: {}
Aug 19, 2004 8:43:16 PM net.sf.hibernate.cfg.SettingsFactory
buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
Aug 19, 2004 8:43:16 PM net.sf.hibernate.cfg.Configuration
configureCaches
INFO: instantiating and configuring caches
HUHUHU
******net/sf/cglib/core/KeyFactory
                                                                     
                                                                     
           Stopping service Tomcat-Standalone
Aug 19, 2004 8:43:03 PM org.apache.coyote.http11.Http11Protocol
destroy
INFO: Stoping http11 protocol on 8080
Catalina:type=ThreadPool,name=http8080"
==============================================================
I don't know what was going on.
What does the "net/sf/cglib/core/KeyFactory" message printed out above
mean?
Is there anything wrong with my configuration?
Thanks. I would appreciate any help.
Tung Chau
Murray - 20 Aug 2004 07:42 GMT
> I don't know what was going on.
> What does the "net/sf/cglib/core/KeyFactory" message printed out above
> mean?
> Is there anything wrong with my configuration?
> Thanks. I would appreciate any help.
> Tung Chau

It might be more useful to print out the entire stack trace instead of just
getMessage(). Quite often messages are useless on their own...

See Exception#printStackTrace()
Tung Chau - 20 Aug 2004 20:33 GMT
> > I don't know what was going on.
> > What does the "net/sf/cglib/core/KeyFactory" message printed out above
[quoted text clipped - 7 lines]
>
> See Exception#printStackTrace()

===========================================================
Oh, thanks for the tip. I forgot about that. Here is the the error I
got:
HUHUHU
******net/sf/cglib/core/KeyFactory
java.lang.NoClassDefFoundError: net/sf/cglib/core/KeyFactory
       at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.
java:236)
       at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.
java:791)
       at elearning.db.HibernateUtil.<clinit>(HibernateUtil.java:18)
       at org.apache.jsp.test_jsp._jspService(test_jsp.java:77)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:210)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:2
95)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:247)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
===============================================================
Has anybody had the same NoClassDefFound error? I just had
hibernate2.jar in my /lib directory
Christophe Vanfleteren - 20 Aug 2004 20:41 GMT
> Oh, thanks for the tip. I forgot about that. Here is the the error I
> got:
[quoted text clipped - 3 lines]
>         at
>        
net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.
> java:236)
>         at
<snip part of stacktrace/>
> ===============================================================
> Has anybody had the same NoClassDefFound error? I just had
> hibernate2.jar in my /lib directory

You also need to add the hibernate dependencies to your classpath (/lib
directory). Starting with cglib. I'm pretty sure that hibernate also has
other dependencies, and that this is documented in the documentation that
comes with it.

Signature

Kind regards,
Christophe Vanfleteren

Tung Chau - 20 Aug 2004 22:38 GMT
I found the solution for the above problem already.
It was because I didn't add some third party jar files in the class
path, for examples, odmg.jar ...
Tung Chau


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.