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)java
建立數據庫,id 爲int數據庫
建立數據庫的表:CREATE TABLE books(id INT PRIMARY KEY auto_increment,Bookname VARCHAR(50),Bookprice VARCHAR(40));session
Books bookFirst = (Books)session.get(Books.class, new Long(1));app
這是由於 數據庫id爲integer與long類型數據不匹配!ide
修改.hbm.xml 修改主鍵數據類型爲longhibernate
<id name="id" type="java.lang.Long"> <column name="id" /> <generator class="native" /> </id>xml