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);
}
}
Actually the
getSession() is returning null but why is it so i am not getting it.Pls help me....