為什么會出現(xiàn)空指針異常呢
<mapping resource="com/imooc/model/Seller.hbm.xml"/>
? ?<mapping resource="com/imooc/model/Customer.hbm.xml"/>等語句的使用
? 比如在這節(jié)課中,如果我創(chuàng)建了五條映射語句,<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"/>
而沒有創(chuàng)建對應的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();這兩行有空指針異常
[ 收起全文 ]
2017-04-04
好好看下配置文件,特別是數(shù)據(jù)庫錯了沒,我就是數(shù)據(jù)庫寫錯了
2016-12-01
這里是session出現(xiàn)的控制針,也就是說,你的session為空