When a project in the SSH framework accesses the database, the link is always occupied and not released after the access is completed. As a result, after a period of time, the server does not fail, that is, the connection to the database is required, always stuck
Solution:
1. Configure the hibernate file corresponding to spring:
<Prop key = "hibernate. connection. release_mode"> after_statement </prop> the connection is automatically released after the transaction is committed.
2. Configure transactions
<! -- Spring declarative Transaction Manager -->
<Bean id = "transactionManager"
Class = "org. springframework. orm. hibernate3.HibernateTransactionManager">
<Property name = "sessionFactory" ref = "sessionFactory"/>
</Bean>
<! -- Spring transaction interceptor -->
<Bean id = "transactionInterceptor"
Class = "org. springframework. transaction. interceptor. TransactionInterceptor">
<Property name = "transactionManager" ref = "transactionManager"/>
<Property name = "transactionAttributes">
<Props>
<! -- All Methods Starting with browse, list, load, get, and is use read-only transaction control types -->
<Prop key = "browse *"> PROPAGATION_REQUIRED, readOnly </prop>
<Prop key = "list *"> PROPAGATION_REQUIRED, readOnly </prop>
<Prop key = "load *"> PROPAGATION_REQUIRED, readOnly </prop>
<Prop key = "get *"> PROPAGATION_REQUIRED, readOnly </prop>
<Prop key = "is *"> PROPAGATION_REQUIRED, readOnly </prop>
<! -- All methods are subject to transaction control. If no transaction exists, a new transaction is created. -->
<Prop key = "*"> PROPAGATION_REQUIRED </prop>
</Props>
</Property>
</Bean>
<! -- Automatic proxy -->
<Bean
Class = "org. springframework. aop. framework. autoproxy. BeanNameAutoProxyCreator">
<Property name = "beanNames">
<List>
<Value> * Impl </value>
</List>
</Property>
<! -- If this attribute is true, it indicates that the proxy is the interface of the target class rather than the target class. -->
<Property name = "proxyTargetClass">
<Value> true </value>
</Property>
<! -- Dependency injection the transaction interceptor transactionInterceptor defined above -->
<Property name = "interceptorNames">
<List>
<Value> transactionInterceptor </value>
</List>
</Property>
</Bean>