Disable crashing the server when Hibernate panics after oopsing

This commit is contained in:
Leon Hofmeister 2020-10-23 00:15:37 +02:00
parent 2eeb55ed52
commit fccd7e70b1
Signed by: delvh
GPG Key ID: 3DECE05F6D9A647C
1 changed files with 24 additions and 3 deletions

View File

@ -341,15 +341,36 @@ public final class PersistenceManager {
}
private void persist(Object obj) {
transaction(() -> entityManager.persist(obj));
try {
transaction(() -> entityManager.persist(obj));
} catch (EntityExistsException e) {
if (transaction.isActive())
transaction.rollback();
EnvoyLog.getLogger(PersistenceManager.class).log(Level.WARNING,
String.format("Could not persist %s: entity exists already.", obj));
}
}
private void merge(Object obj) {
transaction(() -> entityManager.merge(obj));
try {
transaction(() -> entityManager.merge(obj));
} catch (IllegalArgumentException e) {
if (transaction.isActive())
transaction.rollback();
EnvoyLog.getLogger(PersistenceManager.class).log(Level.WARNING,
String.format("Could not merge %s: entity doesn't exist.", obj));
}
}
private void remove(Object obj) {
transaction(() -> entityManager.remove(obj));
try {
transaction(() -> entityManager.remove(obj));
} catch (IllegalArgumentException e) {
if (transaction.isActive())
transaction.rollback();
EnvoyLog.getLogger(PersistenceManager.class).log(Level.WARNING,
String.format("Could not remove %s: entity didn't exist (for the database).", obj));
}
}
/**