parent
76ee1be76c
commit
8f4c721a7d
1 changed files with 21 additions and 7 deletions
|
@ -339,11 +339,21 @@ public class JpaMapStorageProviderFactory implements
|
|||
this.validatedModels.clear();
|
||||
}
|
||||
|
||||
volatile boolean initialized;
|
||||
|
||||
private void lazyInit() {
|
||||
if (emf == null) {
|
||||
/*
|
||||
On Quarkus, and EMF can be created even when the database is currently not available.
|
||||
Closing the EMF is not an option, as it is managed by Quarkus.
|
||||
Therefore, try to initialize it as often as needed, especially for the addSpecificNamedQueries()
|
||||
which would cause failures later if not initialized here.
|
||||
*/
|
||||
if (!initialized) {
|
||||
synchronized (this) {
|
||||
if (emf == null) {
|
||||
this.emf = createEntityManagerFactory();
|
||||
}
|
||||
if (!initialized) {
|
||||
JpaMapUtils.addSpecificNamedQueries(emf);
|
||||
|
||||
// consistency check for transaction handling, as this would lead to data-inconsistencies as changes wouldn't commit when expected
|
||||
|
@ -353,13 +363,17 @@ public class JpaMapStorageProviderFactory implements
|
|||
|
||||
// consistency check for auto-commit, as this would lead to data-inconsistencies as changes wouldn't roll back when expected
|
||||
EntityManager em = getEntityManager();
|
||||
try {
|
||||
em.unwrap(SessionImpl.class).doWork(connection -> {
|
||||
if (connection.getAutoCommit()) {
|
||||
throw new ModelException("The database connection must not use auto-commit. For Quarkus, auto-commit was off once JTA was enabled for the EntityManager.");
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
em.close();
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue