Hibernate 3.1 's query, the main code is as follows:
Project Project = (project) session.get (Project.class, 1);
The primary key type in the MS SQL 2005 database is bigint.
Using the main aspect test, it appears: org.hibernate.TypeMismatchException:Provided ID of the wrong type. Expected:class Java.lang.Long, got class Java.lang.Integer
Or use JUnit tests to appear: Java.lang.ClassCastException:java.lang.Integer cannot be cast to Java.lang.Long
Error Reason:
Session.get (Project.class, 1); The parameter 1 in the method is of type int, is automatically converted to integer, and the ProjectID property in the Project class is long, It corresponds to the configuration file is also Java.util.Long, so there is Java.lang.Integer cannot is cast to Java.lang.Long exception,
Workaround:
The code is changed to Project Project = (project) session.get (Project.class, 1L), 1 plus L in the argument, indicating that it is a long type, is automatically converted to long, or project project = ( Project) Session.get (Project.class, New Long (1));