0

I'm using Spring 3.0 and hibernate 4.x, but I'm facing issue on transaction management. I'm using @Transactional annotation in service layer but it is taking too long time to save large amount of data into Database.

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.

1 Answers1

0

@Transactional is not responsible for your performance. 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

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

innodb_buffer_pool_size=614M

too many indexes?

Primary Key Genration

Why is MySQL InnoDB insert so slow?

hope this things will help you out

Community
  • 1
  • 1
Ashish Jagtap
  • 2,799
  • 3
  • 30
  • 45