hibernate查询时报错:Noentityfoundforquery
先贴上代码:
public Account getAccountByName(String name) {
玉兰花诗句异地恋情话最暖心短句// TODO Auto-generated method stub
怎么写新闻稿String hql = "lect a from Account a where name =?";
Query query = null;
九气拈痛丸query = ateQuery(hql);
Account account = (Account) query.tParameter(1, name)携手共进
.getSingleResult();汤阴梦幻谷
return account;
土地规划}
错误的原因:使⽤了getSingleResult()⽅法,当查询时,如果数据库中确实有数据,不会报错;但是当数据库中没有数据时,则⽆法getSingleResult,所以会报:
摄影作品赏析No entity found for query 这个错。在⽹上查到资料介绍:getSingleResult的源码⾥有这样⼀句: @throws EntityNotFoundException if there is no result;
解决⽅法:⽤其他⽅式代替getSingleResult()