Set timeout for 30-40 queries

时间:2016-04-25 09:29:20

标签: java hibernate prepared-statement

I want to set query timeout for almost 30-40 queries in a Hibernate Java application. Is there a way in which I can set the time out for all the 30-40 queries without using statement.setQueryTimeout for each query?

1 个答案:

答案 0 :(得分:0)

使用:

  query.setMaxResult(40); // for set bound of query results.

然后

  session.getTransaction().setTimeout(3); //set transaction timeout to 3 seconds
  session.getTransaction().begin();

每次调用方法时,都应该传递(指定)查询结果的数量(setFirstResult,setMaxResult)。 或者在你的hibernate配置中使用hibernate.c3p0.timeout。