2

我需要根据它的 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;
}

系统参数组:

@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;
}
4

1 回答 1

0

您还必须从的列表中删除该SystemParameter实体:SystemParameterGroupSystemParameter

systemParameterGroup.getSystemParameterList().remove(systemParameter);

这个问题与这个有关。

于 2013-10-22T16:26:47.727 回答