日期:2014-05-17  浏览次数:20806 次

Hibernate Spring的整合求高手指导快要崩溃了
Java code
public Book selectBook(String ISBN){
        System.out.println(ISBN);
    List list=this.getHibernateTemplate().find("from Book where ISBN=?",ISBN); //报错就是这一行
    Book book=null;
    if(list.size()>0)
    {
        book=(Book)list.get(0);
    }
    return book;
    }

/////*******************////
Java code
public interface BookDao {
        
        public void addBook(Book book);
        public void deleteBook(String ISBN);
        public void updateBook(Book book);
        public Book selectBook(String ISBN);
        
    }


///////////////**************////////
Java code
public interface StudentService {
public Student selectStudent(String readerId);
}


网页报错/////////////***///////
java.lang.NullPointerException
org.Dao.impl.BookDaoImpl.selectBook(BookDaoImpl.java:14)
org.action.BookAction.selectBook(BookAction.java:107)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)

------解决方案--------------------
跟踪一下看看你的this.getHibernateTemplate()是不是空的?
------解决方案--------------------
BookDaoImpl有木有继承HibernateDaoSupport?
------解决方案--------------------
那你怎么配置的sessionFactory贴出来
------解决方案--------------------
探讨

1.在配置文件中配置
<!-- hibernateTemplate设置 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
……