-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate Tutorial Chapter1 - cant compile HibernateUtil
PostPosted: Sun Jun 29, 2008 10:49 am 
Newbie

Joined: Sun Jun 29, 2008 10:27 am
Posts: 5
Location: london
Dear Hibernaters,

I'm trying to work through the Tutorial example in Chapter1 and have become stuck. I'm trying to compile HibernateUtil.java but I'm getting compiler errors that the classes referenced in the Import statements cant be found.

The source code is as follows,
Code:
package util;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

   private static final SessionFactory sessionFactory;

   static {
      try {
         // Create the SessionFactory from hibernate.cfg.xml
         sessionFactory = new Configuration().configure().buildSessionFactory();
      }catch (Throwable ex){
         // Make sure you log the exception, as it might be swalledd
         System.err.println("Initial SessionFactory creation failed." + ex);
         throw new ExceptionInInitializerError(ex);
      }
   }

   public static SessionFactory getSessionFactory(){
      return sessionFactory;
   }
}


The Javac statement and error message is shown below.
    D:\Data\java\eclipse\com.eclipse.hibernate\src>javac -cp ../lib/hsqldb.jar util/
    HibernateUtil.java
    util\HibernateUtil.java:3: package org.hibernate does not exist
    import org.hibernate.*;
    ^
    util\HibernateUtil.java:4: package org.hibernate.cfg does not exist
    import org.hibernate.cfg.*;
    ^
    util\HibernateUtil.java:8: cannot find symbol
    symbol : class SessionFactory
    location: class util.HibernateUtil
    private static final SessionFactory sessionFactory;
    ^
    util\HibernateUtil.java:21: cannot find symbol
    symbol : class SessionFactory
    location: class util.HibernateUtil
    public static SessionFactory getSessionFactory(){
    ^
    util\HibernateUtil.java:13: cannot find symbol
    symbol : class Configuration
    location: class util.HibernateUtil
    sessionFactory = new Configuration().configure().buildSe
    ssionFactory();
    ^
    5 errors


I cant find the "org.hibernate.*" location. I've looked in the "hsqldb.jar" file but cant see anything there.

Does anyone have any pointers or suggestions please.

Regards
Robert.


Top
 Profile  
 
 Post subject: compilation problem - answer
PostPosted: Sun Jun 29, 2008 11:22 am 
Newbie

Joined: Sun Jun 29, 2008 10:27 am
Posts: 5
Location: london
Dear Hibernators, sometimes when you write down the problem it helps you to discover the solution yourself. This is whats happened with me I think. At the beginning of the tutorial it says copy the lib directory from Hibernate to your development src directory, but the file below "hibernate3.jar" is not in this directory its in the top-level hibernate directory. So when I copied the Lib dir I was missing this file and so my Javac complained about the "import" statements. I copied over the Hibernate3 file and re-ran the Javac with the correct -classpath reference to Hibernate3.jar and it complied fine. I hope this can help someone else next time.

    +lib
    antlr.jar
    cglib.jar
    asm.jar
    asm-attrs.jars
    commons-collections.jar
    commons-logging.jar
    hibernate3.jar
    jta.jar
    dom4j.jar
    log4j.jar


Regards
Robert.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 10:33 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Yes, the most simple problems can sometimes become the most frustrating.

I put together a simple and straight forward tutorial on how to set up your computer with a Hibernate3 environment and get started with Hibernate and JPA. You might find some of the tips and tricks helpful:

http://www.hiberbook.com/HiberBookWeb/learn.jsp?tutorial=01howtogetstartedwithhibernate

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 12:12 pm 
Newbie

Joined: Sun Jun 29, 2008 10:27 am
Posts: 5
Location: london
Thank you Cameron.

The site looks really good.

I've finished the Tutorial 1 on the Hibernate.org site and managed to work my through it (just about!). Still need to do more work on it though and may look through your site suggestion for further reading.

Do you happen to know any good sites for looking at the Spring Framework? I believe Hibernate and Spring are a very common combination these days.

Regards
Robert.

P.S Thanks for your congrats on the Java Ranch certifications site !! :)


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