[英]JPA - Issues removing child entities on bidirectional mapping
我需要刪除名為基礎上,it's ID“SystemParamater” 子實體 。
我正在嘗試做的是:
- Begin Tran
SystemParameter param EntityManager.find(SystemParameter.class,<paremeter.id>)
EntityManager.remove(param)
-Commit tran
但是實體沒有被移除。
刪除子實體的正確方法是什么?
在下面,您可以找到我的實體:
系統參數:
@Entity
@Table(name = "system_parameters")
@Cacheab le
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SystemParameter extends BasicEntity {
private static final long serialVersionUID = -6416605270912358340L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "paramName", length = 50, nullable = false)
private String paramName;
@Column(name = "paramValue", length = 255, nullable = false)
private String paramValue;
@Column(name = "encrypted", nullable = false)
@Type(type = "yes_no")
private Boolean encrypted = Boolean.FALSE;
@ManyToOne
@JoinColumn(name = "groupId", nullable = false)
private SystemParameterGroup parameterGroup;
}
SystemParameterGroup:
@Entity
@Table(name = "system_parameter_groups", uniqueConstraints = { @UniqueConstraint(columnNames = { "searchKey" }) })
@Cacheable
public class SystemParameterGroup extends BasicEntity {
private static final long serialVersionUID = -1762633144642103487L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name", length = 50, nullable = false)
private String name;
/**
* Description.
*/
@Column(name = "description", length = 255, nullable = false)
private String description;
/**
* Search key.
*/
@Column(name = "searchKey", length = 50, nullable = false)
private String searchKey;
/**
* System parameter list.
*/
@OneToMany(fetch = FetchType.EAGER, mappedBy = "parameterGroup", cascade = CascadeType.ALL, orphanRemoval = true)
@OrderBy("paramName")
private List<SystemParameter> systemParameterList;
}
你必須刪除SystemParameter
還從實體SystemParameterGroup
的的名單SystemParameter
:
systemParameterGroup.getSystemParameterList().remove(systemParameter);
這個問題與此有關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.