The entity class corresponding to the role table looks as follows:
@Entity
@Table(name="role",catalog="task_mgmt_system")
class Role {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@Column(name = "id")
private var id:Int? = null
@Column(name="role")
private var role : String? = null
@ManyToMany(mappedBy = "roles",cascade = [CascadeType.PERSIST])
private var users:Set<User>? = null
// ... Getters and Setters
}
In the many-to-many relationship between User and Role entities, the ownership is with theUser entity so the @ManyToMany annotation in the Role entity is defined with the mappedBy attribute.