This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Error" Watch "Hibernate Error" New topic
Author

Hibernate Error

Lal Prasad Rajendraprasad
Greenhorn

Joined: Jul 13, 2008
Posts: 2
Hi All,

I'm new to Hibernate.I'm trying to compile a sample Hibernate program(with a pointbase connection).I'm getting the below error.Can anybody help me in this case.

Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:38)

The java code is as below.


package roseindia.tutorial.hibernate;

import org.hibernate.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


/**
* @author Deepak Kumar
*
* http://www.roseindia.net
* Hibernate example to inset data into Contact table
*/
public class FirstExample {
public static void main(String[] args) {
Session session = null;


try{


// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();


System.out.println("Getting session factory");


session =sessionFactory.openSession();


}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}

}
}


Thanks in advance
Lal
gopal venu
Ranch Hand

Joined: Jan 06, 2006
Posts: 55
If you do session.Close() no need for session.flush().
First check whether the session you got from openSession is null or not.
2nd remove the sessionl.flush from code and see
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Hibernate Error
 
It's not a secret anymore!