关于hibernate的问题,不知道什么原因,我写的是 一个查询语句,结果后台执行的是一个update语句,我执行的查询代码:
String hql="select b from Blog b where b.bloger.id='"+bloger.getId()+"'";
Query query=this.getSession().createQuery(hql);
List lt=query.list();报错信息:信息: org.hibernate.exception.DataException: could not update: [edu.myblog.ssh.entity.Blog#5]高手,高手在哪里,麻烦了,谢谢了,
String hql="select b from Blog b where b.bloger.id='"+bloger.getId()+"'";
Query query=this.getSession().createQuery(hql);
List lt=query.list();报错信息:信息: org.hibernate.exception.DataException: could not update: [edu.myblog.ssh.entity.Blog#5]高手,高手在哪里,麻烦了,谢谢了,
from Blog b where b.bloger.id='"+bloger.getId()+"'
看看
Query query=this.getSession().createQuery("Blog b where b.bloger.id=:blogid");
query.setString("blogid","bloger.getId()");
试试看
试过了,还是没用,一样的错误,怎么回事呢,这明明是查询语句啊,怎么执行的却是一条update语句,
设个断点看看!
我之前有查询出 最新的10条博文,即 from Blog b order by b.createTime desc
Query query =this.getSession().createQuery(hql);
query.setFirstResult(0);
query.setMaxResults(10);
是不是这个原因呢,查询过一次就不让查第二次了?
String hql="from Blog b where b.bloger.id='"+bloger.getId()+"'";
Query query=this.getSession().createQuery(hql);
List lt=query.list();