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
Here is my DAO implementation codeCode:<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="myDataSource" /> <property name="annotatedClasses"> <list> <value>customer.customer</value> <value>customer.categories</value> <value>geography.countries</value> <value>geography.states</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.connection.autocommit">true</prop> </props> </property> </bean> <bean id="mycustomerDAO" class="customer.customerDAOImpl"> <property name="sessionFactory" ref="mySessionFactory"/> </bean>
Here is the code i am using in controller to call this DAO implementation listCountries methodCode: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; @Repository("mycustomerDAO") public class customerDAOImpl implements customerDAO { private HibernateTemplate hibernateTemplate; @Autowired public void setSessionFactory(SessionFactory sessionFactory) { this.hibernateTemplate = new HibernateTemplate(sessionFactory); } @Override public void savecustomer(customer customer) { hibernateTemplate.saveOrUpdate(customer); } @Override @SuppressWarnings("unchecked") public List<customer> listcustomer() { return hibernateTemplate.find("from customer"); } @Override @Transactional public List<countries> listCountries() { return hibernateTemplate.find("from countries order by name"); } @Override public List<categories> listCategories() { return hibernateTemplate.find("from customer_category order by name"); } @Override public List<states> listStates(int id) { return hibernateTemplate.find("from states where country_id="+id+" order by name"); } }
it is throwing null pointer exceptionCode:@RequestMapping("/customer.htm") 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); }
thanks
david


Reply With Quote
