Bug 303360 - Query Timeout property is not working when set at the EM & EMF level
Summary: Query Timeout property is not working when set at the EM & EMF level
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 214910
Blocks:
  Show dependency tree
 
Reported: 2010-02-19 14:17 EST by Yiping Zhao CLA
Modified: 2022-06-09 10:20 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yiping Zhao CLA 2010-02-19 14:17:35 EST
create EntityManager with property "PersistenceUnitProperties.QUERY_TIMEOUT", then retrive the property by using em.getProperties(), you will see "javax.persistence.query.timeout=20" is listed there. But the property doesn't take effect on UpdateObjectQuery, as a result the execution of "UPDATE...." as for updating locked relationship for locked entity won't return. 

Because of the problem, the PessimisticLockingExtendedScopeTestSuite can't be enabled to run.
Comment 1 Yiping Zhao CLA 2010-02-19 14:31:52 EST
For the EntityManagerFactory case, I create EntityManagerFactory using the property, then create Entity Manager from that factory, the property doesn't take effect as well, see code:

Map<String, Object> prop = new HashMap();
prop.put(PersistenceUnitProperties.QUERY_TIMEOUT, 20);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("default", prop);
EntityManager em2 = emf.createEntityManager();
Comment 2 Andrei Ilitchev CLA 2010-02-22 12:51:47 EST
As suggested by Gordon, all query hints passed to createEntityManager method (or to setProperty or setProperties methods) should be applied to all the queries run by this entity manager. 

Note that it would be the user's responsibility to make sure that all the passed hints are compatible with all the queries they run: for instance, setting pessimistic timeout query hint into an entity manager would cause an IllegalArgumentException(ExceptionLocalization.buildMessage("ejb30-wrong-type-for-query-hint".

The hints passed to entity manager would apply to not only the queries created using createQuery or creteNativeQuery method but to core queries internally created and executed by Eclipselink - in this case the update query generated by uow.commit() should has timeout set to 20, too.

The same should happen when query hints passed to createEntityManagerFactory method - even if the ServerSession has been already created: the hints then should be applied for all entity managers created by the factory.

This could be easily implemented in case the query hint could be set in the session (that's the case with query timeout) and then applied to all the queries run with the session.

However if it's not the case (for instance, refresh) - how would you do it?
Note that you can't set refresh flag on all descriptors - that would affect all entity managers, not just one.

Consider creating "template" queries - that would adhere to all the hints passed to createEM - to be associated with ClientSession, then all the queries created by the ClientSession would be clones of the template ones.
BTW this approach would allow (if so desired) to apply the query hints only to the appropriate queries (say, not to apply pessimistic lock timeout hint to template update query).
Comment 3 Peter Krogh CLA 2010-06-04 14:39:13 EDT
2.1 Bug scrubbing, deferring to 2.1.1.
Comment 4 Peter Krogh CLA 2010-07-27 14:28:09 EDT
After talking with Andrei, this has been changed to an enhancement request and targeted for 2.2.0.
Comment 5 Peter Krogh CLA 2010-11-10 11:13:05 EST
Bug Scrubbing for 2.2.0 -> 2.3.0.
Comment 6 Peter Krogh CLA 2011-06-20 14:15:30 EDT
bug scrubbing - this is an enh request
Comment 7 Tom Ware CLA 2012-05-29 10:20:34 EDT
Deferring as enhancement.
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:20:42 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink