deleted entity passed to persist: [dcms.ebridge.market.entity.Reward#]

今天項目中的錯誤:

deleted entity passed to persist: [dcms.ebridge.market.entity.Reward#<null>]


刪除RetaReward 對應的所有的Reward

刪除前先用RetailReward 獲得所有的Reward 然後進行批量的刪除

錯誤代碼如下

    @Override
    public void delAccomplishReward(LoginEmployee user, long retaId)
            throws GenericBusinessException {
        RetaReward retaReward = findByPK(RetaReward.class, retaId);
        List<Reward> rewards = retaReward.getRewards();
        if(null == rewards || rewards.size() == 0){
            return ;
        }
        super.batchDelete(rewards);
    }

當刪除的時候產生了上述的錯誤,應爲刪除rewards的時候的 retaReward還關聯着相應的對象,而被刪除後,還是有對象保留着對這些對象的應用,所以出錯。

    @Override
    public void delAccomplishReward(LoginEmployee user, long retaId)
            throws GenericBusinessException {
        RetaReward retaReward = findByPK(RetaReward.class, retaId);
        List<Reward> rewards = retaReward.getRewards();
        retaReward.setRewards(null);
        if(null == rewards || rewards.size() == 0){
            return ;
        }
        super.batchDelete(rewards);
    }

修正後結果如上

這一塊的關係到JPA對象狀態的變化,關於各個狀態的關係,已經記不清楚了,哪天有時間了再整理一下,完善一下這篇blog。




Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: on near line 1, column 52

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章