不删除时,已删除的对象将通过级联重新保存

时间:2019-02-06 20:42:40

标签: hibernate

我已经看到了几个答案,但是都没有解决我的问题。

org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations):

org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade : Error while trying to delete a Patient object

我什至没有尝试删除,但我将状态设置为-1,并且在应用程序的其他位置将对象过滤为其状态,因此必须将其删除。

我正在尝试将user.status设置为-1

RectTransform

用户在其班上有这个

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FitParentToChildren : MonoBehaviour
{
    #region INTERNAL

    public RectTransform parent;
    public RectTransform[] children;

    public float minX = 100000;
    public float maxX = -100000;
    public float minY = 100000;
    public float maxY = -100000;

    #endregion

    #region INITIALIZATION

    void Awake()
    {
        parent = GetComponent<RectTransform>();
        children = GetComponentsInChildren<RectTransform>();
    }

    void Start()
    {
        SetMinMaxValues();
        FitToChildren();
    }

    #endregion

    #region BEHAVIOURS

    private void FitToChildren()
    {
        parent.sizeDelta = GetNewRect();
        parent.anchoredPosition = GetTopLeftCornerPositon();
    }

    private void SetMinMaxValues()
    {
        for (int i = 1; i < children.Length; i++)
        {
            float tempMinX = children[i].anchoredPosition.x - children[i].sizeDelta.x / 2;
            if (tempMinX < minX) minX = tempMinX;

            float tempMaxX = children[i].anchoredPosition.x + children[i].sizeDelta.x / 2;
            if (tempMaxX > maxX) maxX = tempMaxX;

            float tempMinY = children[i].anchoredPosition.y - children[i].sizeDelta.y / 2;
            if (tempMinY < minY) minY = tempMinY;

            float tempMaxY = children[i].anchoredPosition.y + children[i].sizeDelta.y / 2;
            if (tempMaxY > maxY) maxY = tempMaxY;
        }
    }

    private Vector2 GetNewRect()
    {
        return new Vector2 (maxX - minX, maxY - minY);
    }

    private Vector2 GetTopLeftCornerPositon()
    {
        return new Vector2 (minX, maxY);
    }

    #endregion
}

这在UserGroupMembership中

        user.setType(-1);
        userService.updateUser(user);   

错误是

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "user_id", updatable = false)
@LazyCollection(LazyCollectionOption.FALSE)
private List<UserGroupMembership> groupMemberships = new ArrayList<UserGroupMembership>();

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

我正在更新的实体缺少一些缺失的属性,这些属性被删除了,我通过重新获取实体来重新连接它们,这很好。