I need to remove a child entity called "SystemParamater" based on the it´s id.
What i was trying to do:
- Begin Tran
SystemParameter param EntityManager.find(SystemParameter.class,<paremeter.id>)
EntityManager.remove(param)
-Commit tran
But the entity was not removed.
What´s the correct way to remove a child entity?
Below, you could find my entities:
SystemParameter:
@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;
}
You have to remove the SystemParameter
entity also from the SystemParameterGroup
's list of SystemParameter
:
systemParameterGroup.getSystemParameterList().remove(systemParameter);
This issue is related to this one .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.