OneToMany & ManyToOne mapping Spring Boot / Hibernate

后端 未结 4 1922
生来不讨喜
生来不讨喜 2020-12-18 05:17

I have two tables with foreign key relations. I\'ve tried searching on how to do it and it always leads to OneToMany & ManyToOne mapping. I have these two tables.

<
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 06:01

    Can you move the relationship to a related object like this

    @ManyToOne()
    @JoinColumn(name="role_id", referencedColumnName = "role_id", insertable = false, updatable = false)    
    private UserRole userRole;
    

    and same do for userRole

    @OneToMany(targetEntity=User.class, mappedBy="userRole",cascade=CascadeType.ALL, fetch = FetchType.LAZY)    
    private List user = new ArrayList<>();
    

    Update

    The jar file seems to be corrupted. Try removing the content from the .m2\repository and mvn clean install

    OR

    Right-click your project, select Maven, Update Project, check on Force Update of Snapshots/Releases.

提交回复
热议问题