主要错误信息:
- IllegalArgumentException in class: com.gdcy.bean.Department, getter method of property: id
org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of com.gdcy.bean.Department.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.gdcy.bean.Department.id
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.gdcy.bean.Department.id
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
产生错误原因:映射文件中Department.id的类型不匹配
造成经过:在制作项目中,因为贪方便,Department外键对象使用了String类型,打算只读取它的ID来使用就算了,但又糊涂的在配置文件中设置了<many-to-one>的关系,结果在匹配类型的时候成了Department对象和String对象,因此匹配出错,提示类型不匹配
解决方法:1修改hbm.xml文件的多对一,2bean文件中改回读取Department对象
Orther:以上犯的错误比较特殊,常见的:A表中id为int类型,却在A的bean中将id设置为了String,也会导致上述错误(即java类字段的类型与表字段的类型/长度不一致)