File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes where can I find persistence.HibernateUtil Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "where can I find persistence.HibernateUtil" Watch "where can I find persistence.HibernateUtil" New topic

where can I find persistence.HibernateUtil

S Ali
Ranch Hand

Joined: Aug 23, 2009
Posts: 129
Hi all,
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 :

Please tell me what else will I need ?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

It's something you write yourself (or copy from the book).

[Asking smart questions] [About Bear] [Books by Bear]
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

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:

Good luck!

-Cameron McKenzie
S Ali
Ranch Hand

Joined: Aug 23, 2009
Posts: 129
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
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Largely because those tutorials are very poor.

Please check out this set of tutorials here:

They're mine. If you have any problems with them, I can help you out directly with them. Give it a try!

-Cameron McKenzie
wood burning stoves
subject: where can I find persistence.HibernateUtil
It's not a secret anymore!