3

What I have tried...

Using Criteria:

criteria.setTimeout(1);

=> Zero effect

Using HQL:

return getSession().createQuery("from User").setTimeout(1).list();

=> Zero effect

Even tried it on transaction level:

@Transactional(timeout = 1, readOnly = true, propagation = Propagation.REQUIRES_NEW)

Some effect; after the query is executed an exception is thrown but the transaction is not aborted after 1 second.

This is running on a Jetty server with Atomikos TM.

How can I specify a timeout on a specific query so that the call is aborted after that timeout (which will not be 1 second, this is just to test quicker)?

UPDATE

When running the same test but bypassing Atomikos/Hibernate/Spring (so using plain JDBC) the timeout does work (approximately at least; it will not be exactly 1 second, on H2 it came really close, on Oracle this was sometimes over 2 seconds). The result was as expected: SQLException: ORA-01013: user requested cancel of current operation.

UPDATE

When debugging hibernate I see that the timeout is set on the PreparedStatement but it seems to have no effect.

Stijn Geukens
  • 15,454
  • 8
  • 66
  • 101
  • Propagation.REQUIRES_NEW will suspend current transaction & will create new one, can you try REQUIRED or MANDATORY. – Nayan Wadekar Mar 18 '15 at 17:41
  • Thanks, first attempt was with using REQUIRED (which is the default). I changed it because I read somewhere (can't find it back now) that for a timeout to work REQUIRES_NEW or another (?) was required. – Stijn Geukens Mar 19 '15 at 09:27

0 Answers0