| Summary: | native queries do not use the shared cache | ||||||
|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Chris Delahunt <christopher.delahunt> | ||||
| Component: | Eclipselink | Assignee: | Chris Delahunt <christopher.delahunt> | ||||
| Status: | CLOSED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | ||||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
This is due to two reasons. The following in EJBQueryImpl's executeReadQuery method seems to start the transaction early unnecessarily:
if (getDatabaseQueryInternal().isUserDefined()) {
// and there is an active transaction
if (this.entityManager.checkForTransaction(false) != null) {
// verify whether uow has begun early transaction
if (session.isUnitOfWork() && !((UnitOfWorkImpl) session).wasTransactionBegunPrematurely()) {
// uow begins early transaction in case it hasn't
// already begun.
// TODO: This is not good, it means that no SQL queries
// can ever use the cache,
// using isUserDefined to mean an SQL query is also
// wrong.
((UnitOfWorkImpl) session).beginEarlyTransaction();
}
}
}
The other reason is that revision 8720 for bug 232063 changed the ClassDescriptor's default unitOfWorkCacheIsolationLevel from ISOLATE_NEW_DATA_AFTER_TRANSACTION to ISOLATE_CACHE_AFTER_TRANSACTION.
Created attachment 187862 [details]
proposed patch for isolation level setting
Proposed fix setting the UnitOfWorkCacheIsolationLevel to the original ISOLATE_NEW_DATA_AFTER_TRANSACTION default.
Fix checked into main (revision 8900) and 2.2 (r8901). The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
prior to EclipseLink 2.2 RC1, native queries would return Entity data from the shared cache. For instance: EntityManager em = emf.getEntityManager(); em.find(Employee.class, 1); em.clear(); em.getTransaction().begin(); Query query = em.createNativeQuery("Select ID From EMPLOYEE Where ID=1"); Employee emp = query.getSingleResult(); in EclipseLink 2.2 M6 and previous (2.1 etc), the native query be the same as em.find(Employee.class, 1), returning an entity with all attributes read in as they were in the initial find call. In 2.2 RC1, the shared cache is not used, and the Entity is built using the native query row - in this case it will return an Employee with only the ID set.