Details

Description

In a simple JPQL with left join fetch for a lazy loaded association specified and data cached enabled, first time the query executed, the lazy loaded association get loaded, returned and cached. Subsequent invocation of the same query does NOT "load" and return the association from the query invocation.

The test case call doQuery() twice, i.e. same call path. The first call executes the SQLs and fetches Dept and Employee from the db. Both dept and employee were cached. The second call the Employee was fetched from cache but the Employee.dept remains null even the SQL requests to load dept using "join fetch dept".

The attached test will pass (Employee.dept is loaded; not null) if either:
1) the Employee.dept is marked FetchType.EAGER, or
2) TestNPE2.doquery().... em.detach(emp) is removed.

Albert Lee
added a comment - 29/May/14 14:22 The test case call doQuery() twice, i.e. same call path. The first call executes the SQLs and fetches Dept and Employee from the db. Both dept and employee were cached. The second call the Employee was fetched from cache but the Employee.dept remains null even the SQL requests to load dept using "join fetch dept".
The attached test will pass (Employee.dept is loaded; not null) if either:
1) the Employee.dept is marked FetchType.EAGER, or
2) TestNPE2.doquery().... em.detach(emp) is removed.