态所以我做了一个解决方法。
persistence.xml:
<properties>
<property name="showSql" value="true"/>
<property name="hibernate.dialect" value="${hibernate.dialect:org.hibernate.dialect.Oracle10gDialect}"/>
<propertyname="hibernate.connection.datasource"value="java:/alarmmgr/alarmMonitorDB"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.use_sql_comments" value="false"/>
<property name="hibernate.jdbc.wrap_result_sets" value="false"/>
<property name="hibernate.hibernate.cache.use_query_cache" value="true"/>
<property name="javax.persistence.query.timeout" value="1" />
</properties>
查询:
em.createQuery(query).setHint("javax.persistence.query.timeout", 1)
.setFirstResult(payload.getStart())
.setMaxResults(payload.getSize() > MAX_FETCH ? MAX_FETCH : payload.getSize())
.getResultList()
查询返回了7,000行...但是超时不起作用。
em.unwrap(Session.class).doWork(connection -> {
long maxTimeOutMil = TimeUnit.SECONDS.toMillis(MAX_TIMEOUT);
connection.createStatement().execute("set statement_timeout = " + maxTimeOutMil);
});