hibernate 中的java.lang.NullPointerException
BookDAOImpl.java .....
public String getMaxID() {
String sql = "SELECT MAX(bookId)FROM Books";
List list =this.getHibernateTemplate().find(sql);
Iterator itr = list.iterator();
while(itr.hasNext()){
Books book =(Books)itr.next();
System.out.println(book.getBookId());
}
return null;
}
.....
BookTest.java
public class BookTest {
public static void main(String[] args) {
BookDAOImpl book = new BookDAOImpl();
book.getMaxID();
}
}
用的是hibernate跟spring
运行之后就出现了
Exception in thread "main" java.lang.NullPointerException
at org.fcb.dao.BookDAOImpl.getMaxID(BookDAOImpl.java:58)
at org.fcb.dao.BookTest.main(BookTest.java:18)
一直没找到解决的方法。
第58行是
List list =this.getHibernateTemplate().find(sql);
session由spring管理与实例化吧