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
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
相关文章推荐
- Caused by: org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Integer, got class [Lja
- SSH报错之 Provided id of the wrong type for class model.User. Expected: class java.lang
- hibernate 错误:Provided id of the wrong type for class com.lhaix.pojo.Test. Expected: class java.la
- Provided id of the wrong type for class
- TypeMismatchException: Provided id of the wrong type for class zhongfucheng.user.entity.User.
- TypeMismatchException: Provided id of the wrong type for class zhongfucheng.user.entity.User.
- org.hibernate.TypeMismatchException: Provided id of the wrong type for class
- hibernate.TypeMismatchException: Provided id of the wrong type for class
- hibernate 中 Provided id of the wrong type for class 异常
- Hibernate异常:Provided id of the wrong type for class
- ReactJs 报错 Element type is invalid: expected a string (from built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Me`.
- Expected: class java.lang.Long, got class java.lang.Integer异常处理
- java.lang.IllegalStateException: Driver for test database type [H2] is not available in the classpat
- java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.Has
- Cannot convert 0:0 of type class java.lang.String to class java.lang.Long
- java.lang.IllegalArgumentException: No converter found for return value of type: class
- java.lang.NoSuchFieldError: No static field ib_back of type I in class Lcom/example/demo/R$id; or
- java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.Has
- Android java.lang.NoSuchFieldError: No static field xxx of type I in class Lcom/XX/R$id; or its superclasses
- java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.Has