您的位置:首页 > 编程语言 > Java开发

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

2018-05-19 23:56 1846 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐