我之前测试过sql语句执行更新操作,与是否有主键,和主键是否为空没有关系。但是hibernate执行更新的时候没有主键就报错。
保存的方法如下:
public void update(T entity) {
this.getHibernateTemplate().merge(entity);
} 报错如下:
org.hibernate.exception.ConstraintViolationException: could not inser
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'userid' cannot be null
所以我猜测hibernate内部实现更新的语句应该为:update tableName set culumns... where id =
我的解决办法是自己写sql语句解决。