【发布时间】:2011-07-18 09:58:23
【问题描述】:
我有两个实体,如下所示: 设备:
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "device")
private Set<DeviceLine> deviceLines;
设备线:
@ManyToOne
@JoinColumn(name = "device_uid")
private Device device;
DeviceComponent Manager.Class:
DeviceLinePersistenceManager dlpm = new DeviceLinePersistenceManager();
try {
dpm = new DevicePersistenceManager();
Set<DeviceLine> set = new HashSet<DeviceLine>();
for (LineStatus lineStatus : list) {
Device deviceRetrieval = dpm.findDeviceByIp(lineStatus
.getDeviceIp());
if (deviceRetrieval != null) {
Set<DeviceLine> set1 = deviceRetrieval.getDeviceLines();
if (!set1.isEmpty()) {
Iterator<DeviceLine> iterator = set1.iterator();
while (iterator.hasNext()) {
DeviceLine line = iterator.next();
iterator.remove();
DeviceLine lineToDeleted = dlpm.find(line.getUid());
dlpm.purge(lineToDeleted.getUid());
}
}
dpm.update(deviceRetrieval);
}
}
当运行上面的代码时,我得到 ObjectDeletedException: deleted entity passing to persist。
我无法删除设备行条目。调用dlpm.purge(..)时抛出异常,帮帮我。
【问题讨论】:
-
清除方法是什么样的?
-
@BOZHO,purge 方法如下所示... public void purge(D entityToPurge) throws EntityPurgationException {if (entityToPurge==null) { throw new EntityPurgationException( "Entity cannot be purge. Entity找不到。"); } else { EntityTransaction jta = getEntityManager().getTransaction(); jta.begin(); getEntityManager().remove(entityToPurge); jta.commit(); } }