spring - 调用休眠保存导致挂起线程
问题描述
我们使用 Hibernate 和 Spring 使用 DAO 模式,其中应用程序为每个数据库调用调用一个单独的 DAO 类。我们使用 SQL Server 作为我们的数据库。
一段时间以来,我们看到对 Hibernate 的保存调用只会导致线程挂起,而我们对此一无所知。相同的代码在不同的环境中工作(单独的服务器、单独的数据库服务器但相同的版本)。
我们使用的是 Hibernate 4.3.10,自 2 年以来,应用程序没有任何变化。
可能出了什么问题?
调用保存的类的代码粘贴在下面。BusinessAlerts 只是一个 POJO 类。
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void persistBusinessAlert(BusinessAlerts businessAlert) throws DAOException {
if (businessAlert == null) {
return;
}
try {
currentSession().save(businessAlert);
} catch (HibernateException e) {
throw new DAOException(e.getMessage(), e);
}
}
我们已经确定了线程堆栈跟踪,但我无法在此处完整发布。
DB 的 Hibernate 属性是:
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<tx:annotation-driven transaction-manager="priceTransactionManager" />
<bean class="mro.util.CryptoPropertyPlaceholderConfigurer">
<property name="location" value="common_db.properties" />
</bean>
<bean id="priceDataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${alert.db.url}" />
<property name="username" value="${alert.db.username}" />
<property name="password" value="${alert.db.password}" />
</bean>
<bean id="priceSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="priceDataSource" />
<property name="annotatedClasses">
<list>
<value>BusinessAlerts</value>
<value>Executions</value>
<value>AlertCodes</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="priceTransactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="priceSessionFactory" />
</bean>
</beans>
currentSession()
是一个 Hibernate 调用,当我们找到更多关于它的信息时,就会出现这种情况:
protected final org.hibernate.Session currentSession() throws org.springframework.dao.DataAccessResourceFailureException;
0 aload_0 [this]
1 invokevirtual org.springframework.orm.hibernate4.support.HibernateDaoSupport.getSessionFactory() : org.hibernate.SessionFactory [10]
4 invokeinterface org.hibernate.SessionFactory.getCurrentSession() : org.hibernate.Session [11] [nargs: 1]
9 areturn
Line numbers:
[pc: 0, line: 129]
Local variable table:
[pc: 0, pc: 10] local: this index: 0 type: org.springframework.orm.hibernate4.support.HibernateDaoSupport
解决方案
推荐阅读
- php - php二进制基数排序实现
- sql - 是否有更快地将图像或 PDF 写入数据库的优化?
- gradle - Gradle 任务:复制依赖项、重命名和取消归档
- java - 将字符串日期(如 20200917 iso 日期)转换为可读的日期格式 android
- reactjs - 将函数传递给子组件
- c# - 如何正确重启一个actor系统并将其重新加入刚刚离开的akka集群?
- linux - LD_PRELOAD='/something/$LIB/libmyx.so' myprogram 在不同条件下如何展开?
- excel - 搜索槽列(从 2 到 1001 的单元格)并比较每个单元格中的日期以从同一行中提取数据
- cxf - Apache cxf 和大型 SOAP 请求
- c# - 将值从 Object[,] Array 复制到 Object[][] Array