Results 1 to 20 of 20
Like Tree1Likes
  • 1 Post By Tolls

Thread: Hibernate spring integration session factory null pointer exception

  1. #1
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Hibernate spring integration session factory null pointer exception

    I am developing a Struts 2-Spring 3-Hibernate 4 integrated web application.Whenever I run the application on web server it is always giving Null Pointer exception because of Session Factory being null.
    Please suggest me some solution as I am stuck in this problem for a long time.
    I have placed spring configuration file,Dao Implementation class and web.xml as follows:

    spring-config.xml

    <?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-3.0.xsd">

    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location">
    <value>/WEB-INF/databaseConfig.properties</value>
    </property>
    </bean>
    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="${db.driverClassName}" />
    <property name="url" value="${db.databaseurl}" />
    <property name="username" value="${db.username}" />
    <property name="password" value="${db.password}" />
    </bean>

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSes sionFactoryBean">

    <property name="packagesToScan" value="in.nic.eservicebook.pojo" />
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
    <list>
    <value>in.nic.eservicebook.pojo.Title</value>
    <value>in.nic.eservicebook.pojo.BloodGroup</value>
    <value>in.nic.eservicebook.pojo.Community</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>

    </props>
    </property>
    </bean>


    <bean id="MasterDao" class="in.nic.eservicebook.dao.MasterDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    </beans>

    MasterDaoImpl.java

    package in.nic.eservicebook.dao;

    import in.nic.eservicebook.pojo.BloodGroup;
    import in.nic.eservicebook.pojo.Community;
    import in.nic.eservicebook.pojo.Title;
    import in.nic.util.HibernateUtil;
    import java.util.List;
    import org.hibernate.HibernateException;
    import org.hibernate.SessionFactory;

    import org.hibernate.Session;

    import org.springframework.beans.factory.annotation.Autow ired;
    import org.springframework.stereotype.Repository;

    public class MasterDaoImpl implements MasterDao {

    SessionFactory sessionFactory;


    public SessionFactory getSessionFactory() {
    return sessionFactory;
    }


    public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
    }


    @SuppressWarnings("unchecked")
    public List<Title> listTitle() {
    List<Title> titleList = null;
    Session session=null;

    try {
    session = getSessionFactory().getCurrentSession();
    session.beginTransaction();


    titleList=(List<Title>)session.createQuery("from Title").list();
    session.getTransaction().commit();
    }
    catch (Exception e) {
    e.printStackTrace();
    session.getTransaction().rollback();

    }

    finally
    {
    session.close();
    }
    return titleList;
    }


    @SuppressWarnings("unchecked")
    public List<BloodGroup> listBloodGroup() {
    List<BloodGroup> bloodGroupList = null;
    Session session = getSessionFactory().openSession();
    session.beginTransaction();
    try {


    bloodGroupList=(List<BloodGroup>)session.createQue ry("from BloodGroup").list();
    session.getTransaction().commit();

    }
    catch (Exception e) {
    e.printStackTrace();
    session.getTransaction().rollback();

    }

    finally
    {
    session.close();
    }
    return bloodGroupList;
    }

    @SuppressWarnings("unchecked")
    public List<Community> listCommunity() {
    List<Community> communityList = null;
    Session session = getSessionFactory().openSession();
    session.beginTransaction();
    try {


    communityList=(List<Community>)session.createQuery ("from Community").list();
    session.getTransaction().commit();
    }
    catch (Exception e) {
    e.printStackTrace();
    session.getTransaction().rollback();

    }
    finally
    {
    session.close();
    }
    return communityList;
    }

    }

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>esb</display-name>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-config.xml
    </param-value>
    </context-param>
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatch er </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener
    </listener-class>
    </listener>
    <welcome-file-list>
    <welcome-file>eservicebook/index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Hibernate spring integration session factory null pointer exception

    1. re-post the code with code tags so it is readable. There is a button in the advanced post editor.
    2. add the actual exception stacktrace you get
    3. remember and apply 1. and 2. for future posts in any forum (not for me, to help yourself get answers sooner)

    Guide For New Members
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Re: Hibernate spring integration session factory null pointer exception

    I am developing a Struts 2-Spring 3-Hibernate 4 integrated web application.Whenever I run the application on web server it is always giving Null Pointer exception because of Session Factory being null.
    Please suggest me some solution as I am stuck in this problem for a long time.
    I have placed Exception Stacktrace, spring configuration file,Dao Implementation class and web.xml as follows:

    Exception Stacktrace

    Java Code:
    	java.lang.NullPointerException
    	in.nic.eservicebook.dao.MasterDaoImpl.listTitle(MasterDaoImpl.java:52)
    	in.nic.eservicebook.actions.PrepopEmpIdentityPrimaryDetailsAction.execute(PrepopEmpIdentityPrimaryDetailsAction.java:54)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	java.lang.reflect.Method.invoke(Unknown Source)
    	com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
    	com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
    	org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
    	org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
    	org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:432)

    spring-config.xml


    Java Code:
    <?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-3.0.xsd">
    
    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="location">
    <value>/WEB-INF/databaseConfig.properties</value>
    </property>
    </bean>
    <bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName" value="${db.driverClassName}" />
    <property name="url" value="${db.databaseurl}" />
    <property name="username" value="${db.username}" />
    <property name="password" value="${db.password}" />
    </bean>
    
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSes sionFactoryBean">
    
    <property name="packagesToScan" value="in.nic.eservicebook.pojo" />
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
    <list>
    <value>in.nic.eservicebook.pojo.Title</value>
    <value>in.nic.eservicebook.pojo.BloodGroup</value>
    <value>in.nic.eservicebook.pojo.Community</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    
    </props>
    </property>
    </bean>
    
    
    <bean id="MasterDao" class="in.nic.eservicebook.dao.MasterDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    
    </beans>
    MasterDaoImpl.java

    Java Code:
    package in.nic.eservicebook.dao;
    
    import in.nic.eservicebook.pojo.BloodGroup;
    import in.nic.eservicebook.pojo.Community;
    import in.nic.eservicebook.pojo.Title;
    import in.nic.util.HibernateUtil;
    import java.util.List;
    import org.hibernate.HibernateException;
    import org.hibernate.SessionFactory;
    
    import org.hibernate.Session;
    
    import org.springframework.beans.factory.annotation.Autow ired;
    import org.springframework.stereotype.Repository;
    
    public class MasterDaoImpl implements MasterDao {
    
    SessionFactory sessionFactory;
    
    
    public SessionFactory getSessionFactory() {
    return sessionFactory;
    }
    
    
    public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
    }
    
    
    @SuppressWarnings("unchecked")
    public List<Title> listTitle() {
    List<Title> titleList = null;
    Session session=null;
    
    try {
    session = getSessionFactory().getCurrentSession();
    session.beginTransaction();
    
    
    titleList=(List<Title>)session.createQuery("from Title").list();
    session.getTransaction().commit();
    }
    catch (Exception e) {
    e.printStackTrace();
    session.getTransaction().rollback();
    
    }
    
    finally
    {
    session.close();
    }
    return titleList;
    }
    
    
    @SuppressWarnings("unchecked")
    public List<BloodGroup> listBloodGroup() {
    List<BloodGroup> bloodGroupList = null;
    Session session = getSessionFactory().openSession();
    session.beginTransaction();
    try {
    
    
    bloodGroupList=(List<BloodGroup>)session.createQue ry("from BloodGroup").list();
    session.getTransaction().commit();
    
    }
    catch (Exception e) {
    e.printStackTrace();
    session.getTransaction().rollback();
    
    }
    
    finally
    {
    session.close();
    }
    return bloodGroupList;
    }
    
    @SuppressWarnings("unchecked")
    public List<Community> listCommunity() {
    List<Community> communityList = null;
    Session session = getSessionFactory().openSession();
    session.beginTransaction();
    try {
    
    
    communityList=(List<Community>)session.createQuery ("from Community").list();
    session.getTransaction().commit();
    }
    catch (Exception e) {
    e.printStackTrace();
    session.getTransaction().rollback();
    
    }
    finally
    {
    session.close();
    }
    return communityList;
    }
    
    }
    web.xml

    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>esb</display-name>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring-config.xml
    </param-value>
    </context-param>
    <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatch er </filter-class>
    </filter>
    <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener
    </listener-class>
    </listener>
    <welcome-file-list>
    <welcome-file>eservicebook/index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>
    Last edited by nayal_java; 11-15-2013 at 02:59 PM. Reason: Because of another member request

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Hibernate spring integration session factory null pointer exception

    You could have edited your first post :s And you should have reposted the FORMATTED code you have in your source files, as you can clearly see what you have now has no indenting at all.

    In any case the source you post does not match the exception stacktrace. the crash you posted is in PrepopEmpIdentityPrimaryDetailsAction.java on line 54.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Re: Hibernate spring integration session factory null pointer exception

    New Exception Stacktrace

    Java Code:
    java.lang.NullPointerException
    	in.nic.eservicebook.dao.MasterDaoImpl.listTitle(MasterDaoImpl.java:52)
    	in.nic.eservicebook.actions.PrepopEmpIdentityPrimaryDetailsAction.execute(PrepopEmpIdentityPrimaryDetailsAction.java:54)
    	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	java.lang.reflect.Method.invoke(Unknown Source)
    	com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
    	com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
    	org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
    	org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    	com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    	com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
    	org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:432)

    PrepopEmpIdentityPrimaryDetailsAction.java

    Java Code:
    package in.nic.eservicebook.actions;
    
    import com.opensymphony.xwork2.ActionSupport;
    import com.opensymphony.xwork2.ModelDriven;
    
    
    import in.nic.eservicebook.dao.MasterDao;
    import in.nic.eservicebook.dao.MasterDaoImpl;
    import in.nic.eservicebook.pojo.BloodGroup;
    import in.nic.eservicebook.pojo.Community;
    import in.nic.eservicebook.pojo.Title;
    
    import java.util.List;
    public class PrepopEmpIdentityPrimaryDetailsAction extends ActionSupport{
    	
    	private List<Title> titleList;
    	private List<BloodGroup> bloodGroupList;
    	private List<Community> communityList;
    	private MasterDaoImpl mstDao;
    	
    	
    
    	public void setMstDao(MasterDaoImpl mstDao) {
    		this.mstDao = mstDao;
    	}
    
    	public List<Title> getTitleList() {
    		return titleList;
    	}
    
    	public void setTitleList(List<Title> titleList) {
    		this.titleList = titleList;
    	}
    	
    	public List<BloodGroup> getBloodGroupList() {
    		return bloodGroupList;
    	}
    
    	public void setBloodGroupList(List<BloodGroup> bloodGroupList) {
    		this.bloodGroupList = bloodGroupList;
    	}
    
    	public List<Community> getCommunityList() {
    		return communityList;
    	}
    
    	public void setCommunityList(List<Community> communityList) {
    		this.communityList = communityList;
    	}
    
    	public String execute()
    	{
    		mstDao=new MasterDaoImpl();
    		titleList=mstDao.listTitle();
    		bloodGroupList=mstDao.listBloodGroup();
    		communityList=mstDao.listCommunity();
    		return SUCCESS;
    	}
    }

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Hibernate spring integration session factory null pointer exception

    Surely you can trace through your code and figure out the only route in that method that will result in a null pointer exception at that point.
    There's only a handful of lines in that method, so tell us what you think is happening.
    You don't have to say why (though it should start to become obvious), but you should at least be able to say what.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Re: Hibernate spring integration session factory null pointer exception

    Actually in my MasterDaoImpl,

    when I am doing

    Session session=getSessionFactory().getCurrentSession();

    It is giving session value as null

    But I am not able to get what is the reason

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Hibernate spring integration session factory null pointer exception

    Oops, I'm blind. The stacktrace did point to the earlier code, I completely missed the line referencing MasterDaoImpl.listTitle() apparently. My apologies!

    I think vital information is being hidden here, since the crash originates in a finally clause; it might well be that another exception occurred but you don't see it because the finally clause is tossing up a new exception of its own.

    You should change that code to this to prevent the null-pointer you're getting now:

    Java Code:
    finally
    {
    if(session != null){
      session.close();
    }
    }
    And try again - hopefully this time you'll get a different exception that is the real source of your problems.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Hibernate spring integration session factory null pointer exception

    Quote Originally Posted by nayal_java View Post
    Actually in my MasterDaoImpl,

    when I am doing

    Session session=getSessionFactory().getCurrentSession();

    It is giving session value as null

    But I am not able to get what is the reason
    No it's not.
    It's throwing an exception.
    But that assumes that line 52 is:
    Java Code:
    session.close();
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Re: Hibernate spring integration session factory null pointer exception

    After doing as you suggested still getting same error

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Hibernate spring integration session factory null pointer exception

    Then you didn't do as I suggested. There is no way you get the exact same exception on the exact same line if you added a null-check.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Hibernate spring integration session factory null pointer exception

    Post the stack trace.
    Because I will lay good odds on it actually saying line 46 now.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Re: Hibernate spring integration session factory null pointer exception

    As I debug the code,after this line:

    session=getSessionFactory().openSession();

    the control goes to the catch block

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,703
    Rep Power
    5

    Default Re: Hibernate spring integration session factory null pointer exception

    so getSessionFactory() returns a null-value; simple logic. Now you need to figure out when that method would do that; I'm guessing that it does that when the Hibernate configuration in Spring is lacking. The very rich Spring documentation will probably tell you the truth.

    EDIT: grrr, again I make a mistake. See tolls' reply for the real truth.
    Last edited by gimbal2; 11-15-2013 at 04:48 PM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Hibernate spring integration session factory null pointer exception

    getCurrentSession() throws an exception if there is no current session.
    What then happens is that you hit the catch block, log the exception (you haven't said yet if there are more than one stack trace...there has to be), then attempt to rollback a non-existent session...hence NPE.
    gimbal2 likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Re: Hibernate spring integration session factory null pointer exception

    When I does this in the catch block still getting same exception

    if(session !=null)
    {
    session.getTransaction().rollback();
    }

  17. #17
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Re: Hibernate spring integration session factory null pointer exception

    actually my sessionfactory is coming null

    I have configured it in spring-config.xml.

    Do I need to do some other configuration also as the configurations in the spring-config.xml seem to work which I tested

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Hibernate spring integration session factory null pointer exception

    Show us the stack trace.
    Show us all the stack traces, since presumably there's more than one.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  19. #19
    nayal_java is offline Member
    Join Date
    Jul 2010
    Posts
    24
    Rep Power
    0

    Default Re: Hibernate spring integration session factory null pointer exception

    Stack Trace


    Java Code:
    java.lang.NullPointerException
    	at in.nic.eservicebook.dao.MasterDaoImpl.listTitle(MasterDaoImpl.java:40)
    	at in.nic.eservicebook.actions.PrepopEmpIdentityPrimaryDetailsAction.execute(PrepopEmpIdentityPrimaryDetailsAction.java:54)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
    	at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
    	at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    	at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    	at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    	at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
    	at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:432)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)

  20. #20
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Hibernate spring integration session factory null pointer exception

    And which line is line 40?
    If it's the openSession() call then yes, that's your null sessionFactory.

    So have a look through your logs at start up and see if Spring is throwing an exception.
    It usually does if the configuration is mucked up.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Null pointer exception
    By tnrh1 in forum New To Java
    Replies: 1
    Last Post: 10-11-2012, 01:39 PM
  2. Null pointer exception in hibernate
    By kirangk in forum Hibernate
    Replies: 3
    Last Post: 05-14-2012, 03:03 PM
  3. Null Pointer Exception
    By jonytek in forum New To Java
    Replies: 5
    Last Post: 03-02-2011, 07:16 AM
  4. hibernate session = null in the run() method of TimerTask
    By fabs in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-17-2009, 03:12 PM
  5. Integration Problem-Null pointer Exception
    By uhdam in forum AWT / Swing
    Replies: 0
    Last Post: 04-07-2009, 11:46 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •