开发者

ObjectDeletedException: deleted entity passed to persist

开发者 https://www.devze.com 2023-03-21 14:21 出处:网络
I have two entities like the below: Device: @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = \"device\")

I have two entities like the below: Device:

@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&l开发者_如何学Ct;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);
    }
}

when the run the above code iam getting the ObjectDeletedException: deleted entity passed to persist. i am unable to delete the deviceline entries. The exception is thrown when dlpm.purge(..) is called,help me out.


Try dlpm.purge(lineToDeleted);. Currently you are passing the Uid, rather than the entity itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号