ObjectDeletedException:已删除的实体传递给persist

时间:2011-07-18 09:58:24

标签: hibernate jpa

我有两个如下的实体: 设备:

@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "device")
private Set<DeviceLine> deviceLines;

DeviceLine:

@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:删除实体传递给persist。     我无法删除deviceline条目。调用dlpm.purge(..)时抛出异常,帮助我。

1 个答案:

答案 0 :(得分:0)

试试dlpm.purge(lineToDeleted);。目前您正在传递Uid,而不是实体本身。