spring data jpa 버그 레코드 저장 A collection with cascade=\"all-delete-orphan\"was no longer referenced byth...

3373 단어
A collection with cascade=\"all-delete-orphan\"was no longer referenced by the owning entity instance: com.htsc.thfx.framework.entity.user.UserInfo.authorities; nested exception is org.hibernate.HibernateException: A collection with cascade
jpa
package com.htsc.thfx.framework.entity.user;

import com.htsc.thfx.framework.entity.menu.Menu;
import com.htsc.thfx.framework.entity.port.ProductCompany;
import com.htsc.thfx.framework.entity.port.ProductCompanyTemporaryStorage;
import com.htsc.thfx.framework.enums.user.UserInfoAuthStatus;
import com.htsc.thfx.framework.enums.user.UserType;

import javax.persistence.*;
import java.io.Serializable;
import java.util.*;

/**
 * @author K0060021
 * @createtime 2018 7 16 
 *  
 */

@Entity
public class UserInfo implements Serializable {

    @Id
    @Column(length = 50)
    private String username;// 



    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
    @JoinColumn(name = "username", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private Set authorities = new HashSet();


}

새 set만 낡은 set로 바꿀 수 없습니다. 이렇게 안전하게 삭제해야 합니다.
            List save = userAuthorityDao.save(newList);
            // jpa  
            if (userInfo.getAuthorities() == null)
                userInfo.setAuthorities(new HashSet<>());
            userInfo.getAuthorities().clear();
            userInfo.getAuthorities().addAll(save);

 
전재 대상:https://www.cnblogs.com/ronniery/p/10599848.html

좋은 웹페이지 즐겨찾기