From 4b756e42a163a02f2bf29dca930295cfd3c5f0ea Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Thu, 16 Dec 2010 14:37:26 +0000 Subject: fix memory leak : hibernate session is not correctly cleared with batch processing mode --- .../main/java/org/sonar/jpa/session/JpaDatabaseSession.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'sonar-core') diff --git a/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java b/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java index 8390dd8fd6b..5a350117670 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java +++ b/sonar-core/src/main/java/org/sonar/jpa/session/JpaDatabaseSession.java @@ -55,7 +55,6 @@ public class JpaDatabaseSession extends DatabaseSession { public void stop() { commit(); if (entityManager != null && entityManager.isOpen()) { - entityManager.clear(); entityManager.close(); entityManager = null; } @@ -69,9 +68,10 @@ public class JpaDatabaseSession extends DatabaseSession { } else { entityManager.getTransaction().commit(); } + entityManager.clear(); + index = 0; } inTransaction = false; - index = 0; } } @@ -79,7 +79,6 @@ public class JpaDatabaseSession extends DatabaseSession { if (entityManager != null && inTransaction) { entityManager.getTransaction().rollback(); inTransaction = false; - index = 0; } } @@ -110,7 +109,7 @@ public class JpaDatabaseSession extends DatabaseSession { private void internalSave(Object model, boolean flushIfNeeded) { entityManager.persist(model); if (flushIfNeeded && (++index % BATCH_SIZE == 0)) { - flush(); + commit(); } } @@ -123,7 +122,7 @@ public class JpaDatabaseSession extends DatabaseSession { startTransaction(); entityManager.remove(model); if (++index % BATCH_SIZE == 0) { - flush(); + commit(); } } @@ -144,10 +143,6 @@ public class JpaDatabaseSession extends DatabaseSession { } } - public void flush() { - entityManager.flush(); - entityManager.clear(); - } public Query createQuery(String hql) { startTransaction(); -- cgit v1.2.3