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.