hibernateが更新操作を実行する場合、プライマリ・キーがないとエラーが表示されます


私は前に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 tablemName set culumns...where id = ?
私の解決策は自分でsql文を書いて解決することです.