Provided ID of the wrong type for class Pojo. Books. Expected:class Java.lang.Integer, got class Java.lang.Long

Source: Internet
Author: User
Tags generator log4j

Log4j:warn No Appenders could is found for logger (org.hibernate.cfg.Environment).
Log4j:warn 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)

Create a database with an ID of int

CREATE table for database: CREATE TABLE books (ID INT PRIMARY KEY auto_increment,bookname varchar (), Bookprice varchar (40));

Books Bookfirst = (Books) session.get (Books.class, New Long (1));

This is because the database ID does not match the integer with the long type data!

Modified. Hbm.xml
Modify primary key data type to long




Provided ID of the wrong type for class Pojo. Books. Expected:class Java.lang.Integer, got class Java.lang.Long

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.