我之前测试过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语句解决。
hibernate执行更新操作的时候,没有主键会报错,布布扣,bubuko.com
原文:http://blog.csdn.net/zl544434558/article/details/20064861