facebook

please help me:Hibernate QuikStart Errors

  1. MyEclipse Archived
  2.  > 
  3. Documentation
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #249557 Reply

    chenqiusheng
    Member

    Running a new install Eclipse 3.1.1, MyEclipse, 4.1.1, SqlServer2000

    I’m running through the Hibernate Quickstart, and, despite some of the database exmples not matching up, I continued to follow the instructions:

    1) I created an “tryHibernate” table
    2) I went into the database explorer, right-clicked to generate the hibernate mappings
    3) I created the HibernateTest class and pasted in the code provided (see below), adding a few import statements.
    4) When I “run as java application” I get the error below.

    ————————–error message—————————————-
    Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at net.sf.ehcache.CacheManager.<clinit>(CacheManager.java:86)
    at org.hibernate.cache.EhCacheProvider.start(EhCacheProvider.java:124)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:169)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
    at com.genuitec.hibernate.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:49)
    at com.genuitec.hibernate.HibernateTest.main(HibernateTest.java:17)

    —————— provided code from tutorial———————-

    package com.genuitec.hibernate;

    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.Transaction;
    import org.apache.commons.logging.*;

    public class HibernateTest {

    public static void main(String[] args) {
    // Step 1 – Create a new entity
    TryHibernateId message = new TryHibernateId();
    // Step 2 – Set message field
    message.setUsername(“dansheng”);
    message.setPassword(“danshengmy”);

    try {
    // Step 3 – Get a Hibernate Session
    Session session = HibernateSessionFactory.currentSession();
    // Step 4 – Persist entity to database
    Transaction tx = session.beginTransaction();
    session.save(message);
    tx.commit();
    System.out.println(“Save successful.”);
    } catch (HibernateException e) {
    System.out.println(“Save failed.”);
    } finally {
    try {
    // Step 5 – close the session
    HibernateSessionFactory.closeSession();
    } catch (HibernateException e1) {
    // do nothing
    }
    }
    }
    }

    #249579 Reply

    Riyad Kalla
    Member

    Luckily this is easy. If you open your project properties and go to Java Build Path then your libraries tab, do you see all your Hibernate libraries added there? Do you see commons-logging? If not, you need to add it. If you added the libraries to your project when you added Hibernate capabilities, click Add then drill down to WEB-INF/lib and add all the JARs listed. If you didn’t, then click Add Library, then MyEclipse Library then both the Hibernate libraries.

    Now redeploy and try and run your example, commons-logging.jar should be deployed and should avoid that ClassNotFoundException

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: please help me:Hibernate QuikStart Errors

You must be logged in to post in the forum log in