JPA更新多对多删除记录 [英] JPA update many-to-many deleting records
本文介绍了JPA更新多对多删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在两个实体之间有@ManyToMany关系。当我在拥有方执行更新时,JPA似乎从我的数据库中删除所有链接的记录并重新插入它们。对我来说这是一个问题,因为我有一个MySQL触发器,在删除记录之前触发。如何解决这个问题?
I have a @ManyToMany relationship between two entities. When I perform an update on the owning side, it appears that JPA deletes all the linked records from my database and re-inserts them. For me this is a problem because I have a MySQL trigger that fires before a record is deleted. Any ideas on how to get around this problem?
@Entity
public class User {
@Id
@Column(name="username")
private String username;
...
@ManyToMany
@JoinTable(name="groups", joinColumns=
@JoinColumn(name="username", referencedColumnName="username"),
inverseJoinColumns=@JoinColumn(name="groupname",
referencedColumnName="type_id"))
private List<UserType> types;
...
}
@Entity
public class UserType {
@Id
@Column(name="type_id")
private String id;
@ManyToMany(mappedBy="types")
private List<User> users;
...
}
推荐答案
看来我的问题是我没有合并实体。
It appears my problem was that I was not merging the entity.
这篇关于JPA更新多对多删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文