最近在使用hibernate 保存一条记录的时候总是抛出detached entity passed to persist异常,很是苦恼,检查了一下主键生成策略发现没有问题,最后排查持久化的对象数据,发现主键id字段在数据转换的过程中赋值为空字符串了,即:id="" 这样就造成了detached entity passed to persist异常
解决方案:if(condition){
this.id=null;//
}
思想就是,id是uuid自动生成的,避免手动给id赋值
最近在使用hibernate 保存一条记录的时候总是抛出detached entity passed to persist异常,很是苦恼,检查了一下主键生成策略发现没有问题,最后排查持久化的对象数据,发现主键id字段在数据转换的过程中赋值为空字符串了,即:id="" 这样就造成了detached entity passed to persist异常
解决方案:if(condition){
this.id=null;//
}
思想就是,id是uuid自动生成的,避免手动给id赋值