• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

hibernate _ saveorUpdate problem

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to build an application in spring and hibernate.After writing the applicationContext.xml and spring xml file.
I am getting this exception
***********

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:535)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:463)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


the root cause
******************

java.lang.NullPointerException
com.palnar.college.DAO.StaffDAO.saveUser(StaffDAO.java:14)
com.palnar.college.web.StafRegController.onSubmit(StafRegController.java:26)
org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:523)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:463)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


com.palnar.college.DAO.StaffDAO.saveUser

public class StaffDAO extends HibernateDaoSupport{

public void saveUser(StaffReg staff){


getHibernateTemplate().saveOrUpdate(staff);

}

StafRegController
************************
public class StafRegController extends SimpleFormController{

@Override
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {

StaffReg staffreg=(StaffReg)command;
StaffDAO staffdao=new StaffDAO();

staffreg.setId(staffreg.getId());
staffreg.setName(staffreg.getName());

staffdao.saveUser(staffreg);

return new ModelAndView("success");
}


applicationcontext.xml
*****************************
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/samplesdb</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.palnar.college.service.StaffReg</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="connection.pool_size">1</prop>
<prop key="current_session_context_class">thread</prop>
<prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop key="show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate.hibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="StaffDAO"
class="com.palnar.college.DAO.StaffDAO">
<property name="sessionFactory" ><ref local="sessionFactory"/></property>
</bean>


web.xml
******************


<servlet>
<servlet-name>SpringWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringWeb</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>/WEB-INF/jsp/index.jsp</welcome-file>
</welcome-file-list>

<jsp-config>
<taglib>
<taglib-uri>/spring</taglib-uri>
<taglib-location>
/WEB-INF/tld/spring-form.tld
</taglib-location>
</taglib>
</jsp-config>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


java.lang.NullPointerException
com.palnar.college.DAO.StaffDAO.saveUser(StaffDAO.java:14)


What happens on line 14 of StaffDAO? This is where you have a null pointer.
 
subha nair
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply...

My line 15 in StaffDAO is

getHibernateTemplate().saveOrUpdate(staffReg);

and the class is


package com.palnar.college.DAO;

import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.palnar.college.service.StaffEdit;
import com.palnar.college.service.StaffReg;

public class StaffDAO extends HibernateDaoSupport{
public void saveUser(StaffReg staffReg){

System.out.println(staffReg.getId());
System.out.println(staffReg.getName());

getHibernateTemplate().saveOrUpdate(staffReg);


}

}

Please help me out...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic