IllegalArgumentException occurred while calling setter for property

IllegalArgumentException occurred while calling setter for property [cn.awei.domain.Student.id (expected type = java.lang.Integer)]; target = [cn.awei.domain.Student@3e235a46], property value = [2]
    org.hibernate.property.access.spi.SetterMethodImpl.set(SetterMethodImpl.java:99)
    org.hibernate.tuple.entity.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:258)
    org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:633)
    org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:4616)
    org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1470)
    org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1454)

Console会报如下错误:

 ERROR org.hibernate.property.access.spi.SetterMethodImpl - HHH000123: IllegalArgumentException in class: cn.awei.domain.Student, setter method of property: id
ERROR org.hibernate.property.access.spi.SetterMethodImpl - HHH000091: Expected type: java.lang.Integer, actual value: java.lang.String

IllegalArgumentException此异常表明向方法传递了一个不合法或不正确的参数。
接着往下看setter for property [cn.awei.domain.Student.id (expected type = java.lang.Integer)];
该错误应该是出现在实体及实体映射部分,查看代码如下:

**错误的:**
      <id name="id" type="java.lang.String">
            name="id" />
            class="uuid"/>
        id>
**改正的**
    <id name="id" >
            name="id" />
            class="native"/>
        id>

因为我的实体中对应主键类型属性定义的是Integer数据类型所以这个有个错误。实验了很多次搞了很久才明白。native是针对Integer对象的自增是对应数据库中的Integer存入的,而这里,你写个String类型的uuid,它就不认可了!牢记!!!

你可能感兴趣的:(IllegalArgumentException occurred while calling setter for property)