【问题标题】:ObjectDeletedException: deleted entity passed to persistObjectDeletedException:已删除的实体传递给持久化
【发布时间】: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(); } }

标签: hibernate jpa


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-11-22
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 2013-06-03
    • 2013-06-26
    • 1970-01-01
    • 2017-04-01
    • 2018-09-22
    相关资源
    最近更新 更多