Hibernate version: 3.2.0.cr2
Name and version of the database you are using: MySQL 4.1
I'm inserting some data (about 12000 rows) in the DB:
Code:
//...
@PersistenceContext
private EntityManager em;
public void loadTeamFile() {
//...
while(it.hasNext()){
//...
Team t = new Team(/*...*/);
em.persist(t);
//...
}
}
The problem is that hibernate opens and reliases the connection after each persist(). So my EJB works really slow, and after a number (8-10 000 ) inserts an exception (actualy - different exceptions) may occur.
What can i do to avoid this?
I've tried to use
Code:
em.getTransaction().begin()
//...
em.getTransaction().commit()
but this is not allowed for Container-Managed EntityManager...
Heere is the example log:
Code:
2006-08-20 20:31:09,402 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] executing identity-insert immediately
2006-08-20 20:31:09,402 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 1)
2006-08-20 20:31:09,402 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
2006-08-20 20:31:09,402 DEBUG [org.hibernate.SQL] insert into Team (razdel, kod) values (?, ?)
2006-08-20 20:31:09,402 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] Natively generated identity: 12563
2006-08-20 20:31:09,402 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 2)
2006-08-20 20:31:09,402 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
2006-08-20 20:31:09,402 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 1) (open ResultSets: 0, globally: 0)]
2006-08-20 20:31:09,402 DEBUG [org.hibernate.event.def.AbstractSaveEventListener] executing identity-insert immediately
2006-08-20 20:31:09,402 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to open PreparedStatement (open PreparedStatements: 0, globally: 1)
2006-08-20 20:31:09,402 DEBUG [org.hibernate.jdbc.ConnectionManager] opening JDBC connection
2006-08-20 20:31:09,402 DEBUG [org.hibernate.SQL] insert into Team (razdel, kod) values (?, ?)
2006-08-20 20:31:09,402 DEBUG [org.hibernate.id.IdentifierGeneratorFactory] Natively generated identity: 12564
2006-08-20 20:31:09,418 DEBUG [org.hibernate.jdbc.AbstractBatcher] about to close PreparedStatement (open PreparedStatements: 1, globally: 2)
2006-08-20 20:31:09,418 DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
2006-08-20 20:31:09,418 DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 1) (open ResultSets: 0, globally: 0)]