当前位置: 代码迷 >> J2EE >> hibernate dao方法里面一个非常非常简单的有关问题
  详细解决方案

hibernate dao方法里面一个非常非常简单的有关问题

热度:100   发布时间:2016-04-17 23:26:38.0
hibernate dao方法里面一个非常非常简单的问题
   public void updateBookSnum(Integer isbn,Integer num){
try {
Session session = this.getHibernateTemplate().getSessionFactory().openSession();
Query query = session.createQuery("update book b set b.snum="+num+" where b.isbn="+isbn+" "); 
query.executeUpdate();
session.close();
System.out.println("bookdao updateBookSnum调用成功!");
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}


红色的地方 报错了   报错内容是 book is not mapped [update book b set b.snum=9 where b.isbn=555


我的数据库  的列 snum  isbn 都是Interger  就是Int类型的  传进来的数据也是int类型的  book模型里面 显示的也是  
private Integer isbn;private Integer snum;  为什么就会出错呢  ??? 到底是什么错呢?? 谢谢大家~
------解决思路----------------------
把你book的实体类和hbm都发一下
------解决思路----------------------
在HQL语句中所有Hibernate里映射的都是实体类开头都得大写,如果在sql语句中是可以不考虑大小写的
------解决思路----------------------
在HQL语句中,是对对象进行操作 你把里面的book换成Book,列换成Book类中的属性试一下
  相关解决方案