By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,649 Members | 1,490 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,649 IT Pros & Developers. It's quick & easy.

Hibernate: Exception in thread "main" java.lang.NullPointerException

P: 1
I wrote a prgram using hibernate and got the following error:
Exception in thread "main" java.lang.NullPointerException
at hibernateTutorial.FirstExample.main(FirstExample.j ava:36)
/hibernate.cfg.xml not found
So i am new to this topic please help
Thanks in advance.
Please find the code attached below:

public class FirstExample {


public static void main(String[] args) {
Session session = null;

try{
// This step will read hibernate.cfg.xml


SessionFactory sessionFactory = new

Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set


System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(3);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();
Aug 1 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.