When using spring's hibernatedaosupport, the error is as follows:
Java.lang.ClassCastException:java.lang.String cannot is cast to Java.lang.Integerat Org.hibernate.type.IntegerType.set (integertype.java:64) at Org.hibernate.type.NullableType.nullSafeSet ( nullabletype.java:154) at Org.hibernate.type.NullableType.nullSafeSet (nullabletype.java:136)
The entity classes are as follows:
public class user{ private int id; private String name; public int getId () { return ID; } public void setId (int id) { this.id = ID; } Public String GetName () { return name; } public void SetName (String name) { this.name = name; } }
The code for the DAO layer is as follows:
public void Select (String id) { List result = This.gethibernatetemplate (). Find ("From User where id=?", New Object[] {ID}); }
The reason for the error is that the id attribute of the user class in the entity class is of type Integer, but the query condition ID passed is of type string. The string is changed to an int type and is resolved incorrectly.
public void Select (int id) { List result = This.gethibernatetemplate (). Find ("From User where id=?", new object[] { ID});
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Use Hibernatetemplate or Hibernatedaosupport to type conversion errors in spring