Hi All pls help me i am getting following exception..
Code:
java.lang.NullPointerException
at org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSession(HibernateDaoSupport.java:140)
at com.uk.DaoImpl.Operations.save(Operations.java:9)
at com.uk.client.Client.main(Client.java:19)
Code:
package com.uk.DaoImpl;
import com.uk.Model.Person;
public class [b]Operations[/b] extends [b]BaseHibernateDAO[/b] {
public void save(Person person) {
try {
getSession().save(person);//THE PROBLEM IS HERE,RETURNING NULL.
} catch (RuntimeException re) {
System.out.println("catch...");
re.printStackTrace();
}
}
}
Code:
package com.uk.DaoImpl;
import java.io.Serializable;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class [b]BaseHibernateDAO [/b]extends [b]HibernateDaoSupport [/b]implements
IBaseHibernateDAO {
protected final Log log = LogFactory.getLog(getClass());
/**
* @see org.appfuse.dao.Dao#saveObject(java.lang.Object)
*/
public void saveObject(Object o) {
getHibernateTemplate().saveOrUpdate(o);
}
/**
* @see org.appfuse.dao.Dao#getObject(java.lang.Class, java.io.Serializable)
*/
@SuppressWarnings("unchecked")
public Object getObject(Class clazz, Serializable id) {
Object o = getHibernateTemplate().get(clazz, id);
if (o == null) {
throw new ObjectRetrievalFailureException(clazz, id);
}
return o;
}
/**
* @see org.appfuse.dao.Dao#getObjects(java.lang.Class)
*/
@SuppressWarnings("unchecked")
public List getObjects(Class clazz) {
return getHibernateTemplate().loadAll(clazz);
}
/**
* @see org.appfuse.dao.Dao#removeObject(java.lang.Class,
* java.io.Serializable)
*/
@SuppressWarnings("unchecked")
public void removeObject(Class clazz, Serializable id) {
getHibernateTemplate().delete(getObject(clazz, id));
}
}
The Client pgm is:
Code:
package com.uk.client;
import com.uk.DaoImpl.BaseHibernateDAO;
import com.uk.DaoImpl.Operations;
import com.uk.Model.Person;
public class [b]Client [/b]extends [b]BaseHibernateDAO [/b]{
/**
* @param args
*/
public static void main(String[] args) {
Person person = new Person();
person.setName("shivam");
person.setAge(85);
Operations operation = new Operations();
operation.save(person);
}
}
applicationcontext.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/shivam">
</property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
</bean></beans>