org.hibernate.HibernateException: Found shared references to a collection: com.jinyi.ihome.module.ex...
程序员文章站
2022-04-16 08:52:13
...
HomeExpress类中有如下字段:
@OneToMany
@JoinColumn(name="OWNER_PHONE", referencedColumnName="EXPRESS_PHONE", insertable = false, updatable = false)
@NotFound(action = NotFoundAction.IGNORE)
@Setter
private List<Owner> phoneUsers;
phoneUsers 这种一对多的字段在执行 .saveAndFlush() 方法进行更新时候容易出现该异常,解决办法是在执行更新前将其赋值为null就可以了,为了避免每次执行更新前都要将其设置为null,可以在其所在的实体类中加入如下代码:
@PreUpdate
private void onUpdate() {
phoneUsers = null;
}
这个方法会在执行.saveAndFlush()前自动调用,就可以提前将phoneUsers 设置为null了。
推荐阅读
-
Hibernate :Found shared references to a collection
-
Hibernate JPA —— could not insert 或 detach entity passed to persist 或Found shared references 错误
-
hibernate异常Found shared references to a collection
-
org.hibernate.HibernateException: Found shared references to a collection: com.jinyi.ihome.module.ex...
-
HibernateSystemException: Found shared references to a collection:
-
HibernateException: Found shared references to a collection 解决办法
-
Hibernate :Found shared references to a collection
-
Hibernate异常Found shared references的解决办法