【发布时间】:2019-01-10 15:27:59
【问题描述】:
我有两个具有 OneToMany 关系的实体
资源.java
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL}, mappedBy="resource", orphanRemoval = true)
private Set<Skills> skills = new HashSet<Skills>();
另一个实体是 Skills.java
@Id
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name = "RESOURCE_CODE", unique = false, nullable = false, foreignKey = @ForeignKey(name = "fk_resource_primary_skills_map_resource_code"))
@Audited(withModifiedFlag = true, targetAuditMode = RelationTargetAuditMode.NOT_AUDITED, modifiedColumnName = "RESOURCE_CODE_MOD")
private Resource resource;
我会一次性添加/更新/删除资源技能。 为此,我正在尝试清除所有现有技能并添加一套新技能
resourceObject.getSkills().clear();
resourceObject.getSkills().addAll(skills);
添加/删除工作正常。但更新不起作用。 我看到下面的异常
a different object with the same identifier value was already associated with the session
我尝试了 entityManager.flush 和新事务,但没有任何效果
【问题讨论】:
-
如何更新技能?
-
我得到了更新的技能。我清除现有集添加新集
标签: java hibernate jpa jakarta-ee