Spring data JPA- Hibernate Many to Many relation is inserting null in link entity table

前端 未结 2 1362
孤城傲影
孤城傲影 2021-01-27 03:36

I have many to many relation between user to role

USER ENTITY:

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import         


        
相关标签:
2条回答
  • 2021-01-27 04:22

    try saving the role also, you haven't stored the role after changing it in addrole function in user entity.

    0 讨论(0)
  • 2021-01-27 04:31

    UserRole attributes aren’t the table’s primary ID so @Id should not be on these 2.

    You should add an ID attribute to UserRole and annotate that with @Id and @GeneratedValue.

    The @ManyToOne will result in a foreign key in the database

    0 讨论(0)
提交回复
热议问题