views:

221

answers:

2

Hi, For glassfish v2, I have searched through the web and I cannot find anyway to specify query timeout when using TopLink essential query hint. We have another option to migrate to EclipseLink but that is not feasible.

have tried the solution in http://forums.oracle.com/forums/thread.jspa?threadID=974732&tstart=-1 but it seems the DatabaseQuery which one could set a timeout value is actually for Toplink, not TopLink essential.

Do we have some other way to instruct the JDBC driver for this timeout value other than the query hint? I need to do it on query-basis and not system-basis (which is just to change the value of DISTRIBUTED_LOCK_TIMEOUT)

A: 

According to the documentation of Toplink JPA about Query Hints:

You can use the following TopLink JPA hints (for more details on these settings please refer to the TopLink documentation)

  • fetchSize Takes an Integer. Allows the user to set the fetchSize of a TopLink query.
  • referenceClass Takes a class. Override the target class of the query.
  • cacheUsage Takes an Integer. Describes how TopLink makes use of the cache for querying objects.
  • refresh Takes a Boolean. Set to true if the cache should be refreshed from the database.
  • lockMode Takes an Integer. Set for Pessimistic Locking.
  • expression Takes a TopLink Expression object. Used for querying using TopLink API.
  • timeout Takes an Integer. Sets the the query timeout in milseconds.

So my understanding is that you should be able to do that:

Query queryEmployeesByFirstName = em.createNamedQuery("findAllEmployeesByFirstName");
queryEmployeesByFirstName.setHint("timeout", new Integer(5000));

Not tested though.

Pascal Thivent
A: 

Thank you for your answer, I have already tried that and it does not work.

yhzs8