wood burning stoves*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "where can I find persistence.HibernateUtil" Watch "where can I find persistence.HibernateUtil" New topic
Author

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 :
antlr.jar
asm.jar
asm-attrs.jars
c3p0.jar
cglib.jar
commons-collections.jar
commons-logging.jar
dom4j.jar
hibernate3.jar
hsqldb.jar
jta.jar

Please tell me what else will I need ?


SCJP 6
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

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


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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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
    
    1

Largely because those tutorials are very poor.

Please check out this set of tutorials here:

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

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

-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where can I find persistence.HibernateUtil
 
Similar Threads
No Persistence provider for EntityManager named helloworld
Class HibernateUtil cannot be resolved
hibernate with HSQL db - Acquisition Attempt Failed Error
Do not carry my list on page XHTML
what happen if we call another method within the transaction block