Spring Boot @ManyToManyMap删除而不是更新

wqnecbli  于 2023-08-04  发布在  Spring
关注(0)|答案(2)|浏览(123)

UserWorkRelatedInfo实体:

@JsonBackReference
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "user_work_related_info_roles",
            joinColumns = @JoinColumn(name = "user_work_related_info_id"),
            inverseJoinColumns = @JoinColumn(name = "role_id"))
    private Set<Role> roles;

字符串
在角色实体中,我没有指定任何内容!
我的Hibernate日志是

Hibernate: 
    update
        user_work_related_info 
    set
        handover_protocol_id=?,
        lead_id=?,
        position_id=?,
        stack=?,
        user_id=? 
    where
        id=?
2023-08-03 12:50:02.127  INFO 66838 --- [0.0-8080-exec-2] e.g.erp.utils.audit.CrudEventListener    : Admin updated UserWorkRelatedInfo : {"id":11,"stack":null,"position":null,"handoverProtocol":null}
Hibernate: 
    delete 
    from
        user_work_related_info_roles 
    where
        user_work_related_info_id=?


我尝试使用Equals()和hashCode(),也尝试将mappedBy添加到Role实体中,我从User实体中删除了orphanRemoval//(我的User实体是OneToOne与UserWorkRelatedInfo实体),还更改了级联类型,-- Im使用实体图进行连接。此外,当即时通讯更新的领导是列userWorkRelatedInfo时,也会发生这种情况

km0tfn4u

km0tfn4u1#

请检查您的问题是否与此答案相关。

https://stackoverflow.com/questions/75572714/hibernate-unwanted-delete-after-update-in-manytomany-relationship

字符串

bwntbbo3

bwntbbo32#

你试过使用级联类型MERGE或PERSIST吗?

相关问题