I'm trying to learn hibernate from java persistence with hibernate book , however I'm having trouble executing the helloworld example .
My compiler wont find the persistence.*; package nor the HibernateUtil class .
I have the following jars included as suggested in the book :
Bear is right. You're not going to find that HibernateUtil or HibernateContext class, or whatever it's called, inside one of the standard "Hibernate Core" jar files.
I too found this very frustrating when I started to learn Hibernate. It seems every book used a HibernateUtil class, and if you opened up to a random chapter, and hadn't read that one or two pages at the beginning of the book that created the HibernateUtil class, then you were lost. Even worse, sometimes you'll find the HibernateUtil class in chapter 2, then it's referenced in chapter 14, but you didn't read chapter 7 where HibernateUtil was updated or changed. Frustrating indeed.
The HibernateUtil class usually does a couple of basic things, and usually has methods to do each of the following:
1. Initialize a Hibernate Configuration or AnnotationConfiguration object
2. Create and cache a SessionFactory using a singleton pattern.
3. Create and return Hibernate Session objects to calling programs
4. Sometimes wrapper methods for starting and committing transactions
5. Sometimes other helper methods.
Here's the HibernateUtil class I use in my little book on Hibernate. However, there is no standardized set of methods for a HibernateUtil class, so this HibernateUtil will be different from other HibernateUtil classes that are used in other books. But it will give you an idea of what types of method and structure a HibernateUtil class might take:
Joined: Aug 23, 2009
yes you are right it was mentioned later in the book I guess I was over excited . Anyway I decided I should try with a more simple example from rose india . But why does the following give NPE ??
Cameron Wallace McKenzie
author and cow tipper