gpt4 book ai didi

How to set session time out(如何设置会话超时)

转载 作者:bug小助手 更新时间:2023-10-24 21:15:14 25 4
gpt4 key购买 nike



I have an old project which is using Spring (3.2.1.RELEASE) and hibernate-core (3.6.10.Final). Basically, I need to set the time out when any query takes more than 30 seconds to execute.

我有一个旧项目,它使用的是Spring(3.2.1.RELEASE)和Hibernate-core(3.6.10.Final)。基本上,我需要设置执行任何查询所需的时间超过30秒。


Please find below my existing spring configuration:

请在下面找到我现有的弹簧配置:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">

<!-- Hibernate Transaction Manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<jee:jndi-lookup id="dataSource" jndi-name="${jndi.x.name}"></jee:jndi-lookup>
<jee:jndi-lookup id="dataSourceConfig" jndi-name="${jndi.y.name}"></jee:jndi-lookup>



<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.globally_quoted_identifiers">true</prop>
<prop key="hibernate.connection.CharSet">utf8</prop>
<prop key="hibernate.connection.characterEncoding">utf8</prop>
<prop key="hibernate.connection.useUnicode">false</prop>
</props>
</property>
</bean>

<!-- configure hibernate session factory for Local database -->

<bean id="sessionFactoryConfig"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourceConfig"/>
<property name="configLocations">
<list>
<value>classpath:hibernate.cfg.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!-- <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop> -->
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.globally_quoted_identifiers">true</prop>
<prop key="hibernate.connection.CharSet">utf8</prop>
<prop key="hibernate.connection.characterEncoding">utf8</prop>
<prop key="hibernate.connection.useUnicode">false</prop>

</props>
</property>
</bean>
</beans>

My hibernate.cfg.xml is find below:

我的hibernate.cfg.xml如下:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory name="sessionFactoryConfig">
<!-- Please keep this in alphabetical order (ascending) -->
<mapping resource="mappings/named_queries.xml" />
<mapping class="dummy.test" />
<mapping class="dummy.test2" />

</session-factory>
</hibernate-configuration>

I have seen the following config:

我看到了以下配置:


hibernate.c3p0.timeout

But based on what I have read, it will remove unused connection in a pool not time out an active session if it is taking more than 30 seconds.

但根据我所读到的,它将删除池中未使用的连接,而不是超时的活动会话,如果它需要超过30秒。


Any idea how I can achieve the global time out functionality?

你知道我怎么才能实现全球超时功能吗?


更多回答
优秀答案推荐

The Hibernate configuration is for setting query timeout is:

用于设置查询超时的休眠配置为:


javax.persistence.query.timeout

If using Springboot application properties:

如果使用SpringBoot应用程序属性:


spring.jpa.properties.javax.persistence.query.timeout=123

更多回答

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com