简体   繁体   English

使用@Transactional的Spring 3.x和Hibernate 4.x事务管理问题

[英]Spring 3.x and hibernate 4.x transaction management issue using @Transactional

I'm using Spring 3.0 and hibernate 4.x, but I'm facing issue on transaction management. 我正在使用Spring 3.0和Hibernate 4.x,但是我在事务管理方面面临问题。 I'm using @Transactional annotation in service layer but it is taking too long time to save large amount of data into Database. 我在服务层中使用@Transactional批注,但是将大量数据保存到数据库中花费的时间太长。

here is my transaction manager: 这是我的交易经理:

<tx:annotation-driven />
<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

And I'm using this line of code to insert data: 我正在使用以下代码行插入数据:

sessionFactory.getCurrentSession().save(deal);

Please if anybody has the solution, help me out. 如果有人有解决方案,请帮帮我。

@Transactional is not responsible for your performance. @Transactional对您的表现不承担任何责任。 first of all use Batch Processing for large amount of data as follows 首先使用批处理来处理大量数据,如下所示

int i = 0;
for(Deal deal : deals)
    session.save(deal);
    if ( i % 20 == 0 ) { //20, same as the JDBC batch size
        //flush a batch of inserts and release memory:
        session.flush();
        session.clear();
    }
   i++; 
}
session.flush();
session.clear();

read more about Chapter 13. Batch processing 阅读有关第13章的更多信息。批处理

Sometimes it is not the query itself which causes a slowdown - another query operating on the table can easily inserts to slow down due to transactional isolation and locking. 有时,不是查询本身导致速度下降-由于事务隔离和锁定,对表进行操作的另一个查询很容易插入,从而导致速度下降。 read more about this external factores 阅读有关此外部因素的更多信息

link1 链接1

innodb_buffer_pool_size=614M innodb_buffer_pool_size = 614M

too many indexes? 索引太多?

Primary Key Genration 主键生成

Why is MySQL InnoDB insert so slow? 为什么MySQL InnoDB插入这么慢?

hope this things will help you out 希望这件事对你有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM