These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: AnnotationConfiguration Null pointer Exception
PostPosted: Mon Nov 02, 2009 11:09 am 
Newbie

Joined: Sat Oct 31, 2009 9:14 am
Posts: 1
Hi,
Its looks simple but strange and not able to find why this null pointer exception when making AnnotationConfiguration object.

FirstExample.java
=============

package roseindia.tutorial.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;


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

try{

System.out.println("before annotation");
AnnotationConfiguration cfg=new AnnotationConfiguration();
System.out.println("after annotation");

SessionFactory sessionFactory =cfg.configure().buildSessionFactory();

session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Transaction trn=session.beginTransaction();
session.beginTransaction();
Contact contact = new Contact();
contact.setId(6);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
trn.commit();
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();

}

}
}

=========
Err==> before annotation
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:39)
Configration file :
---------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="SessionFactoryName">
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">tiger</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@10.184.74.103:1521:orcl</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<mapping class="roseindia.tutorial.hibernate.Contact" resource="Contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Contact.java File :
------------------
package roseindia.tutorial.hibernate;



import java.io.Serializable;

import javax.persistence.*;
@Entity
@Table (name="Contact")
public class Contact implements Serializable {
@Column (name="FirstName")
private String firstName;

@Column (name="Lastname")
private String lastName;
@Column (name="email")
private String email;

@Id @GeneratedValue
@Column (name="ID")
private long id;

public String getEmail() {
return email;
}

/**
* @return First Name
*/
public String getFirstName() {
return firstName;
}

/**
* @return Last name
*/
public String getLastName() {
return lastName;
}

/**
* @param string Sets the Email
*/
public void setEmail(String string) {
email = string;
}

/**
* @param string Sets the First Name
*/
public void setFirstName(String string) {
firstName = string;
}

/**
* @param string sets the Last Name
*/
public void setLastName(String string) {
lastName = string;
}

/**
* @return ID Returns ID
*/
public long getId() {
return id;
}

/**
* @param l Sets the ID
*/
public void setId(long l) {
id = l;
}



}



Could anyone pls help on this?
Regards,
Sankar. S


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.