Results 1 to 15 of 15
  1. #1
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Angry HibernateUtil cannot be resolved

    Hi All

    I am trying to execute my first program on Hibernate. I am executing the HelloWorld program in the book "Java persistance with hibernate".
    I have downloaded hibernate-distribution-3.5.2-Final i have taken all the jar files under the folder "hibernate-distribution-3.5.2-Final\lib\required" and added them to the class path

    I am trying to execute the program

    Java Code:
    public class HelloWorld {
          public static void main(String[] args) {
               
              // First unit of work
               Session session = HibernateUtil.getSessionFactory().openSession();
               Transaction tx = session.beginTransaction();
               Message message = new Message("Hello World");
               Long msgId = (Long) session.save(message);
               tx.commit();
               session.close();
    
              // Second unit of work
              Session newSession=HibernateUtil.getSessionFactory().openSession();
    
             Transaction newTransaction = newSession.beginTransaction();
             List messages = newSession.createQuery("from Message m order by
    ? m.text asc").list();
    
             System.out.println( messages.size() + " message(s) found:" );
     
             for ( Iterator iter = messages.iterator();iter.hasNext(); ) {
                      Message loadedMsg = (Message) iter.next();
                      System.out.println( loadedMsg.getText() );
             }
             
              newTransaction.commit();
              newSession.close();
    
              // Shutting down the application
             HibernateUtil.shutdown();
         }
    }
    But i am getting the error Unable to resolve the class HibernateUtil. Please let help me in resolving this problem

    Thanks in advance
    Fierof2

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Hi,
    Can you show all stack trace exception?
    Skype: petrarsentev
    http://TrackStudio.com

  4. #4
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default

    Its a compile time exception that i am getting. The eclipse is not resolving the import statement.

    I dont know under which jar is the HibernateUtil.java file is

    The required folder under hibernate-distribution-3.5.2-Final-dist\hibernate-distribution-3.5.2-Final\lib\required contains the following jars

    antlr-2.7.6.jar
    commons-collections-3.1.jar
    dom4j-1.6.1.jar
    javassist-3.9.0.GA.jar
    jta-1.1.jar
    slf4j-api-1.5.8.jar

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,184
    Rep Power
    20

    Default

    None of those are hibernate jars.
    They're the jars Hibernate depends on.

    Do a search for hibernate_core_<version>.jar.

  6. #6
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default

    Hi Tolls

    I have also added the hibernate3.jar file to the class path and i am still facing the same problem.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,184
    Rep Power
    20

    Default

    What classpath and how are you compiling this?

  8. #8
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default

    I have added these to the java build path in eclipse. Please see the attached screenshot for more information.
    Attached Thumbnails Attached Thumbnails HibernateUtil cannot be resolved-hibernatejars.jpg  

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,184
    Rep Power
    20

    Default

    Does that hibernate jar have HibernateUtil in it?
    What package is HibernateUtil in?

  10. #10
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default

    I am not sure in which package HibernateUtil is present but the code provided in the book has the following import statements

    import java.util.*;
    import org.hibernate.*;
    import persistence.*;

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,184
    Rep Power
    20

    Default

    Then find out which package it's in.

    Does the tutorial, for example, provide you with one?

    I only ask because (and you'd have noticed this if you'd actually done any hunting at all yourself) there is no HibernateUtil class in Hibernate. They tend to be project specific.

  12. #12
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default

    Thanks a lot Tolls you are great.

    The HibernateUtil is a separate Java file provided by the Book. I went to their site and got this file.

    Thanks a lot for you assistance in helping me.

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  14. #14
    fierof2 is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default

    Hi Erang

    Can you please let me know how to mark this thread as solved. I dont see any option in the reply to mark this thread as solved.

  15. #15
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. HttpServlet Cannot be resolved to a type
    By chizbox in forum Eclipse
    Replies: 3
    Last Post: 07-01-2012, 06:09 PM
  2. Progress bar no updating resolved
    By Haarp425 in forum Threads and Synchronization
    Replies: 2
    Last Post: 06-25-2010, 03:28 AM
  3. Filter cannot be resolved to a type??
    By Harrie_KalaChakra in forum Eclipse
    Replies: 1
    Last Post: 01-15-2010, 10:19 AM
  4. Javax.net is not resolved in Eclipse
    By ansh12 in forum Eclipse
    Replies: 0
    Last Post: 07-04-2009, 01:27 PM
  5. Mark thread RESOLVED.
    By Eranga in forum Suggestions & Feedback
    Replies: 45
    Last Post: 04-02-2008, 11:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •