码迷,mamicode.com
首页 > 编程语言 > 详细

Provided id of the wrong type for class pojo.Books. Expected: class java.lang.Integer, got class java.lang.Long

时间:2018-05-20 00:12:15      阅读:492      评论:0      收藏:0      [点我收藏+]

标签:native   onload   prope   创建   war   please   fir   reload   arch   

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.TypeMismatchException: Provided id of the wrong type for class pojo.Books. Expected: class java.lang.Integer, got class java.lang.Long
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:109)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:906)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:843)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:836)
at test.test.sessions(test.java:34)
at test.test.main(test.java:55)

创建数据库,id 为int

创建数据库的表:CREATE TABLE books(id INT PRIMARY KEY auto_increment,Bookname VARCHAR(50),Bookprice VARCHAR(40));

Books bookFirst = (Books)session.get(Books.class, new Long(1));

这是因为 数据库id为integer与long类型数据不匹配!

修改.hbm.xml
修改主键数据类型为long




Provided id of the wrong type for class pojo.Books. Expected: class java.lang.Integer, got class java.lang.Long

标签:native   onload   prope   创建   war   please   fir   reload   arch   

原文地址:https://www.cnblogs.com/xiaobo-Linux/p/9062175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!