hibernate - java.lang.IllegalStateException: Multiple representations of the same entity with @ManyToMany 3 entities -


I have 3 entities with many institutions:

Role entity:

Strong>

  @ Entity public class role {@Id @GeneratedValue (strategy = GenerationType.IDENTITY) Private integer role ID; Private string roles; Private string description; @ManyToMany (Cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER) @JoinTable (name = "role_permission", includes columns = {@JoinColumn (name = "role_id")}, inverseJoinColumns = {@JoinColumn (name = "permission_id"}} Private set & permit> permissions = new linked H.2sset  gt; ();  

allow unit:

  @ Antiti allow public class {@Id @ generatedValue (strategy = GenerationType.IDENTITY) private int PermissionId; private string Anumtinam; private string description; @ManyToMany (Cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, fetch = FetchType.EAGER) @JoinTable (name = "permissions_car Ykshmta "columns = {@JoinColumn (name =" permission_id ")}, inverseJoinColumns = {@JoinColumn (name =" function_id "}}) Private set & lt; functionality & gt; the functionality = new linked Acsset & lt; & Functionality Unit:   
  @Entity Public Class functionality {@Id @ generatedValue (strategy = GenerationType.IDENTITY) Private Integer ID; The name of the private string;  

I have done the following:

  1. I have created 3 functions

      function1, function2, function3 < / Code> 
  2. Then 2 permissions were created like this:

      a. Functionality 1, allow with functionality 2b. Functionality 2, with permission 3, allow 2  
  3. Then creating a role:

     with  permission 1 and permission 2 role is to get the following exceptions 1 are  

    java.lang.IllegalStateException: merge multiple representations of the same entity [com.persistence.entity.admin.Functionality # 1] Going. Isolated: [com.prististence.entity.admin.Functionality@4729256a]; Separate: [com.persistence.entity.admin.Functionality@56ed25db]

fixed it by removing CascadeType.MERGE on the permission unit


Comments