为什么会出现空指针异常呢
<mapping resource="com/imooc/model/Seller.hbm.xml"/>
<mapping resource="com/imooc/model/Customer.hbm.xml"/>等语句的使用
比如在这节课中,如果我创建了五条映射语句,<mapping resource="com/imooc/model/Seller.hbm.xml"/>
<mapping resource="com/imooc/model/Customer.hbm.xml"/>
<mapping resource="com/imooc/model/Commodity.hbm.xml"/>
<mapping resource="com/imooc/model/Order.hbm.xml"/>
<mapping resource="com/imooc/model/OrderItem.hbm.xml"/>
而没有创建对应的5个持久化类以及映射文件,只有商家和顾客两个。则junit测试
@Test
public void testFromClause(){
String hql = " from Customer ";
Query query = session.createQuery(hql);
List<Customer> customers = query.list();
for(Customer customer : customers){
System.out.println("name:"+customer.getName());
}
}
会抛出指示Query query = session.createQuery(hql);session.close();这两行有空指针异常
[ 收起全文 ]