[ 
https://issues.apache.org/jira/browse/OPENJPA-2925?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Juho Rinta-Paavola updated OPENJPA-2925:
----------------------------------------
    Description: 
Given the entities
{code:java}
@Entity
public class Cat {
    @Id
    @GeneratedValue
    private int id;
    @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
    private List<Cat> children = new ArrayList<>();
    @ManyToOne
    private Cat parent;
    @ManyToOne
    private Human human;
}{code}
and
{code:java}
@Entity
public class Human {
    @Id
    @GeneratedValue
    private int id;
    private String name;
    @OneToMany(mappedBy = "human", fetch = FetchType.EAGER)
    private List<Cat> cats = new ArrayList<>();
} {code}
Calling {{kitten.getParent().getHuman()}} will return the kitten's human 
instead of the expected parent's human, if the kitten has a sibling and both 
kittens belong to the same human.

Failing unit test is available at 
https://github.com/jrp6/openjpa/blob/openjpa-2925/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/TestRecursiveThenNonRecursiveRelationship.java

  was:
Given the entities
{code:java}
@Entity
public class Cat {
    @Id
    @GeneratedValue
    private int id;
    @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
    private List<Cat> children = new ArrayList<>();
    @ManyToOne
    private Cat parent;
    @ManyToOne
    private Human human;
}{code}
and
{code:java}
@Entity
public class Human {
    @Id
    @GeneratedValue
    private int id;
    private String name;
    @OneToMany(mappedBy = "human", fetch = FetchType.EAGER)
    private List<Cat> cats = new ArrayList<>();
} {code}
Calling {{kitten.getParent().getHuman()}} will return the kitten's human 
instead of the expected parent's human, if the kitten has a sibling and both 
kittens belong to the same human.

Failing unit test is available at _TODO link to github_


> Accessing a non-recursive relation of an instance that has been loaded via a 
> recursive relation may produce wrong result
> ------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2925
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2925
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 3.2.2, 4.0.0
>            Reporter: Juho Rinta-Paavola
>            Priority: Major
>
> Given the entities
> {code:java}
> @Entity
> public class Cat {
>     @Id
>     @GeneratedValue
>     private int id;
>     @OneToMany(mappedBy = "parent", fetch = FetchType.EAGER)
>     private List<Cat> children = new ArrayList<>();
>     @ManyToOne
>     private Cat parent;
>     @ManyToOne
>     private Human human;
> }{code}
> and
> {code:java}
> @Entity
> public class Human {
>     @Id
>     @GeneratedValue
>     private int id;
>     private String name;
>     @OneToMany(mappedBy = "human", fetch = FetchType.EAGER)
>     private List<Cat> cats = new ArrayList<>();
> } {code}
> Calling {{kitten.getParent().getHuman()}} will return the kitten's human 
> instead of the expected parent's human, if the kitten has a sibling and both 
> kittens belong to the same human.
> Failing unit test is available at 
> https://github.com/jrp6/openjpa/blob/openjpa-2925/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/recursive/TestRecursiveThenNonRecursiveRelationship.java



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to