Hi Daryl, I can see the oddity but an "inversed" one. I would say that
> // get em 1 > select a from A as a > left join fetch a.bCol > // close em 1 should return 5 instances of A (2 x a1 and 3 x a2). Prefetching will not make instances "distinct". This looks like a bug described in OPENJPA-894 [1]. [1] http://issues.apache.org/jira/browse/OPENJPA-894 Cheers, Milosz > Hello, > Suppose I have entity A with field "bCol" which is a collection of "B". I > have 2 records of A, a1 having 2 B instances in bCol and a2 having 3 B > instances in bCol. I run this query to load the list of all A's and pre > fetch bCol: > > // get em 1 > select a from A as a > left join fetch a.bCol > // close em 1 > > I get 2 instances of A as expected, a1 and a2. Then I edit a2, first by > getting a fresh, deep instance: > > //get em2 > select a from A as a > left join fetch a.bCol > where a.id = 2 > // close em 2 > ... make edit to a2 > // get em3 > em3.merge(a2); > > Then I reload the original list using the first query: > select a from A as a > left join fetch a.bCol > // close em 3 > > This time I get 4 rows with 3 copies (same hashCode) of a2 (apparently one > for each B child in bCol). It's as if the left join fetch turns into a left > join. Adding "distinct" to the query doesn't help. Interestingly I get only > 1 instance of a1 even though it's got 2 in bCol. Note that the reload > happens on em3 - the same that the merge was done. If I call em3.clear() > before reloading, it works as expected, also if I close em3 and get em4 > before reloading the list. > > Am I not understanding something? Is there some aspect of L1 cache I'm not > handling properly? > Thanks. > > OpenJPA 1.2.1. > > -- > Daryl Stultz > _____________________________________ > 6 Degrees Software and Consulting, Inc. > http://www.6degrees.com > mailto:[email protected] >
