作业帮 > 综合 > 作业

报错:No row with the given identifier exists:13,of class:NHibe

来源:学生作业帮 编辑:搜搜做题作业网作业帮 分类:综合作业 时间:2024/07/07 05:37:02
报错:No row with the given identifier exists:13,of class:NHibernateWebDemo.Model.Supply
源代码:
public static IList GetProductBystorstates_AllCount(int state,int audit,string keyword)
{
string hql = "select p from Product_Sup p join p.ProductType_Sup pt where p.ProductState= " + state + "and p.IsAuditing=" + audit + "and p.ProductName like '%" + keyword + "%' or pt.ProductTypeName like'%" + keyword + "%'or p.Effect like'%" + keyword + "%'" + "or p.ProductName='" + keyword + "'or p.Effect='" + keyword + "'or pt.ProductTypeName='" + keyword + "'";
return session.CreateQuery(hql).List();
}
报错:No row with the given identifier exists:13,of class:NHibe
根据PK值找数据库记录没有找到,没有办法转换成对象.请查看外键之类的数据映射.
再问: 新手,这个不怎么理解,麻烦再剖析一下,谢谢!
再答: 你的sql语句返回的是list,那应该是对象吧,所以可能存在你的记录转换成对象的时候有映射不存在。你有使用hibernate不?
再问: 有使用啊,怎么?
再答: 因为hibernate配置你某些列的时候,你肯定是配成对象了,但是有可能外键又导致找不到对应的外键列。 所以建议你检查一下你配置文件,哪些列是配置成映射为对象的,然后你要找回来的那条记录对应的那些外键的记录存在伐。 或者你可以把你的配置文件改成不是对象的。