1.could not execute batch; SQL [insert into tb_student (addr, age, company, email, level, mobile, name, no, remarks, sex, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
问题出现情况:在save时出现的异常。
问题根本原因:字段赋值时有不符合数据库字段设计的值,比如长度超过数据库字段设计的最大值。
2.org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
问题出现情况:在save时出现的异常。
问题根本原因:数据库更新失败,在此处问题具体原因是因为在界面上ID字段是隐藏属性,对象的ID属性设置为自动生成,在save时界面传到controller中的对象ID属性为空,而不是null,因此数据库执行update语句,而不是insert语句。所以导致执行出错。
解决办法:判断对象id是否为空,为空的话设置为null.