Found shared references to a collection org.hibernate.HibernateException

前端 未结 12 1316
一整个雨季
一整个雨季 2020-11-27 15:48

I got this error message:

error: Found shared references to a collection: Person.relatedPersons

When I tried to execute ad

12条回答
  •  Happy的楠姐
    2020-11-27 16:04

    Consider an entity:

    public class Foo{
    private user;
    /* with getters and setters */
    }
    

    And consider an Business Logic class:

    class Foo1{
    List user = new ArrayList<>();
    user = foo.getUser();
    }
    

    Here the user and foo.getUser() share the same reference. But saving the two references creates a conflict.

    The proper usage should be:

    class Foo1 {
    List user = new ArrayList<>();
    user.addAll(foo.getUser);
    }
    

    This avoids the conflict.

提交回复
热议问题