Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.0.3, 1.2.0, 1.3.0, 2.0.0
-
None
-
None
-
Any, tested with Windows
-
Patch Available
Description
Discovered what seems to be a break with JPA Specification 1.0, section 4.4.5.3 (Fetch Joins). The query in question uses the LEFT JOIN FETCH sematic, so there is the expectation that the result list will contain a copy of the entity reference for every match on the right side of the join (the spec uses the example with the query "SELECT d FROM department d LEFT JOIN FETCH d.employees WHERE d.deptno = 1" where 5 employees are members of department(pk=1) the resultlist should have 5 copies of Department(pk=1). )
Now, if I create all of the entities, persist them to the database, but do not clear the persistence context (leaving all the new entities managed by the persistence context still), the query performs as expected. I get multiple copies of the entity I issued the query for, one for each item successfully matching the LEFT JOIN FETCH. In the example I will update shortly, I get:
[junit] --------------------------------------------------
[junit] Executing testQuery001
[junit] Executing named query getAGroup with intData=42 ...
[junit] ResultList size: 8
[junit] 1 EntityA(id=1): 42, Entity A - PK 1
[junit] 1 EntityA(id=1): 42, Entity A - PK 1
[junit] 1 EntityA(id=1): 42, Entity A - PK 1
[junit] 1 EntityA(id=1): 42, Entity A - PK 1
[junit] 1 EntityA(id=2): 42, Entity A - PK 2
[junit] 1 EntityA(id=2): 42, Entity A - PK 2
[junit] 1 EntityA(id=2): 42, Entity A - PK 2
[junit] 1 EntityA(id=2): 42, Entity A - PK 2
However, if I clear the persistence context, forcing OpenJPA to make a fetch from the database, I only get unique instances of the entity I issued the query for, not multiple copies for each match on the right side of the join.
[junit] --------------------------------------------------
[junit] Executing testQuery002
[junit] Clearing persistence context...
[junit] Executing named query getAGroup with intData=42 ...
[junit] ResultList size: 2
[junit] 1 EntityA(id=1): 42, Entity A - PK 1
[junit] 1 EntityA(id=2): 42, Entity A - PK 2
Both tests use the exact same code for everything, except testQuery002 does a em.clear() before running the query.
Attachments
Attachments
Issue Links
- is depended upon by
-
OPENJPA-1365 DISTINCT keyword has no effect with JOIN FETCH queries
- Open
- is related to
-
OPENJPA-135 join fetch not returning duplicate references which not conforming to ejb3.0 spec
- Closed