terrorists
hibernate查询时报错:Noentityfoundforquery
大英百科全书软件
先贴上代码:
public Account getAccountByName(String name) {
// TODO Auto-generated method stub中英文字典
哪有会计培训班
String hql = "lect a from Account a where name =?";
Query query = null;营养学研究生
2013年英语四级考试时间query = ateQuery(hql);
tachyonAccount account = (Account) query.tParameter(1, name)
.getSingleResult();
return account;
}
outstanding是什么意思epad
错误的原因:使⽤了getSingleResult()⽅法,当查询时,如果数据库中确实有数据,不会报错;但是当数据库中没有数据时,则⽆法getSingleResult,所以会报:
艾迪留学
No entity found for query 这个错。在⽹上查到资料介绍:getSingleResult的源码⾥有这样⼀句: @throws EntityNotFoundException if there is no result;
解决⽅法:⽤其他⽅式代替getSingleResult()