Why does Hibernate try to delete when I try to update/insert?

后端 未结 4 601
独厮守ぢ
独厮守ぢ 2020-12-08 01:44

In my app I have these Hibernate-mapped types (general case):

class RoleRule {
  private Role role;
  private PermissionAwareEntity entity; // hibernate-mapp         


        
4条回答
  •  既然无缘
    2020-12-08 02:02

    I'm not sure if this is the solution, but you might want to try:

    @OneToMany(mappedBy = "role")
    

    And not have the @JoinColumn annotation? I think both entities are trying to 'own' the association, which is why the SQL might be messed up?

    Also, if you want to ensure only affected columns get updated, you can use a hibernate-specific annotation on the class:

    @Entity
    @org.hibernate.annotations.Entity(
        dynamicInsert = true, dynamicUpdate = true
    )
    

提交回复
热议问题