Joined: Thu May 05, 2011 1:58 am Posts: 1
|
hi
i am trying to save a object in to Mysql database. its throwing Null pointer exception. Please help me....
MySql-Jdbc-driver : mysql-connector-java-5.0.8 MySql databse version: MySql 5.0 Hibernate version: hibernate-distribution-3.5.0
Error: Exception in thread "Main Thread" java.lang.NullPointerException at com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:649) at com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:587) at com.mysql.jdbc.PreparedStatement.toString(PreparedStatement.java:4068) at java.lang.String.valueOf(String.java:2826) at java.lang.StringBuffer.append(StringBuffer.java:219) at com.mysql.jdbc.trace.Tracer.printParameters(Tracer.aj:240) at com.mysql.jdbc.trace.Tracer.printEntering(Tracer.aj:167) at com.mysql.jdbc.trace.Tracer.entry(Tracer.aj:126) at com.mysql.jdbc.trace.Tracer.ajc$before$com_mysql_jdbc_trace_Tracer$1$f51c62b8(Tracer.aj:45) at com.mysql.jdbc.Connection.registerStatement(Connection.java:5005) at com.mysql.jdbc.Statement.<init>(Statement.java:270) at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:500) at com.mysql.jdbc.Connection.clientPrepareStatement(Connection.java:2187) at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4829) at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4734) at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534) at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116) at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109) at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2395) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2858) at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:268) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:260) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344) at $Proxy0.flush(Unknown Source) at com.sample.test.SampleHibernate.main(SampleHibernate.java:26)
Main Program:
package com.sample.test;
import java.util.Calendar; import java.util.Date;
import org.hibernate.Session;
import com.sample.model.Person;
public class SampleHibernate {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Session session = SampleUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); Person pers = new Person(); pers.setId(new Long(1)); pers.setFirstName("sandeep"); pers.setLastName("velaga"); Date date=Calendar.getInstance().getTime(); pers.setDateOfBirth(date); session.save(pers); session.flush(); }
}
Hibernate.cfg.xml:
<?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> <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property> <property name="hibernate.connection.password">1484</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/sandeep</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property> <property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property> <property name="show_sql">true</property> <!-- mapping files --> <mapping resource="Person.hbm.xml"/> </session-factory> </hibernate-configuration>
Hibernate mapping file(hbm.xml):
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 4 May, 2011 3:14:15 PM by Hibernate Tools 3.4.0.CR1 --> <hibernate-mapping> <class name="com.sample.model.Person" table="PERSON"> <id name="id" type="java.lang.Long"> <column name="PERSON_ID" /> <generator class="assigned" /> </id> <property name="firstName" type="java.lang.String"> <column name="FIRST_NAME" /> </property> <property name="LastName" type="java.lang.String"> <column name="LAST_NAME" /> </property> <property name="dateOfBirth" type="java.util.Date"> <column name="DATE_OF_BIRTH" /> </property> </class> </hibernate-mapping>
Please help me to resolve this issue.
|
|