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 Null Pointer Exception @ SessionFactory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Null Pointer Exception @ SessionFactory" Watch "Null Pointer Exception @ SessionFactory" New topic

Null Pointer Exception @ SessionFactory

Talha Kabakus

Joined: Feb 27, 2010
Posts: 23
Hello to everyone,

I'm new to Hibernate. I just want to do a sample project with Hibernate. But I've been taking exceptions, I'll be happy if someone can help me..
Thanks in advance..

And here's my hibernate.cfg.xml file:

Full stacktrace:
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

The exception says it is being thrown in line 30 in saveOrUpdate. Which line is line 30? If I had to guess, I would imagine it is one of the lines in the catch or finally block. You should have a null check so you aren't trying to rollback the transaction if it is null. In other words, if Hibernate fails on creating a session, the code throws a Null Pointer in the catch block and you don't know what the original exception is. The finally block should have a similar null check for session.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Talha Kabakus

Joined: Feb 27, 2010
Posts: 23
Thanks for your reply Jeanne..

Now I'm taking another exception :

org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping clazz="model.Users"/>

Here's my Users class that is generated Hibernate tools..

I agree. Here's the link:
subject: Null Pointer Exception @ SessionFactory
It's not a secret anymore!