Announcement Announcement Module
No announcement yet.
Hibernate reutrning null in call from controller. problem with annotations Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate reutrning null in call from controller. problem with annotations

    Hi I am using annotations in my dispatcher and controller. but when i make a call to hibernate it is returning null from my DAO object. can you please help. I feel something wrong with the annotations i have placed in the file. help me to locate and rectify the problem

    here is my code in dispatcher servlet for hibernate
    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="myDataSource" />
    <property name="annotatedClasses">
    <property name="hibernateProperties">
    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="">update</prop>
    <prop key="hibernate.connection.autocommit">true</prop>
    <bean id="mycustomerDAO" class="customer.customerDAOImpl">
    <property name="sessionFactory" ref="mySessionFactory"/>
    Here is my DAO implementation code
    import geography.*;
    import java.util.List;
    import org.hibernate.SessionFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.orm.hibernate3.HibernateTemplate;
    import org.springframework.stereotype.Repository;
    import org.springframework.transaction.annotation.Transactional;
    import org.springframework.web.bind.annotation.ModelAttribute;
    public class customerDAOImpl implements customerDAO {
    private HibernateTemplate hibernateTemplate;
    public void setSessionFactory(SessionFactory sessionFactory)
    this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    public void savecustomer(customer customer) {
    public List<customer> listcustomer() {
    return hibernateTemplate.find("from customer");
    public List<countries> listCountries() {
    return hibernateTemplate.find("from countries order by name");
    public List<categories> listCategories() {
    return hibernateTemplate.find("from customer_category order by name");
    public List<states> listStates(int id) {
    return hibernateTemplate.find("from states where country_id="+id+" order by name");
    Here is the code i am using in controller to call this DAO implementation listCountries method
       public ModelAndView customer(HttpServletRequest request,HttpServletResponse response) throws Exception
            ModelMap modelMap = new ModelMap();
            modelMap.addAttribute("customer", new customer());
            modelMap.addAttribute("countries", new countries());
            modelMap.addAttribute("countryList", customerDAO.listCountries());
            return new ModelAndView("customer",modelMap);
    it is throwing null pointer exception


  • #2
    I have fixed this problem. just changed the

    private HibernateTemplate hibernateTemplate;

    public HibernateTemplate hibernateTemplate;

    this was possible after reading some old threads on hibernate in this forum. thanks to all those authors for help