-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: getSession() is returning null
PostPosted: Mon May 18, 2009 7:29 am 
Newbie

Joined: Sat May 09, 2009 2:03 am
Posts: 14
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....


Top
 Profile  
 
 Post subject: Re: getSession() is returning null
PostPosted: Mon May 18, 2009 7:32 am 
Newbie

Joined: Thu Jan 15, 2009 9:54 am
Posts: 12
You need to check your application context file, we need to refer the sessionfactory over there .

can you paste your application context file below


Top
 Profile  
 
 Post subject: Re: getSession() is returning null
PostPosted: Mon May 18, 2009 7:37 am 
Newbie

Joined: Sat May 09, 2009 2:03 am
Posts: 14
applicationcontext.xml
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-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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.