package com.model; // Generated 2016-10-27 14:02:17 by Hibernate Tools 4.3.1.Final /** * CmDept generated by hbm2java */ public class CmDept/* implements java.io.Serializable */{ private String id; private String deptName; public CmDept() { } public CmDept(String id) { this.id = id; } public CmDept(String id, String deptName) { this.id = id; this.deptName = deptName; } public String getId() { return this.id; } public void setId(String id) { this.id = id; } public String getDeptName() { return this.deptName; } public void setDeptName(String deptName) { this.deptName = deptName; } }
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 2016-10-27 14:40:22 by Hibernate Tools 3.5.0.Final --> <hibernate-mapping> <class name="com.model.CmDept" table="CM_DEPT"> <id name="id" type="java.lang.String"> <column name="ID" /> <generator class="sequence"> <param name="sequence">cm_sequence_dept</param> </generator> </id> <property name="deptName" type="java.lang.String"> <column name="DEPTNAME" /> </property> </class> </hibernate-mapping>
以上代码是报错的代码 ! ! !
由于是使用的反向工程建表, 在设计表结构的时候将几个表的id设置成了varchar2型, 导致反向工程生成的实体类的主键id的类型变成String了, 所以当HibernateTemplate在插入数据的时候不认识了, 所以报了这个错误, 从新修改一遍表结构, 将oracle数据库的主键改成number, 将实体类中的id改成Bigdecimal, 还记得要重新生成一遍*.hbm.xml文件, 问题解决