parent
76ee1be76c
commit
8f4c721a7d
1 changed files with 21 additions and 7 deletions
|
@ -339,11 +339,21 @@ public class JpaMapStorageProviderFactory implements
|
||||||
this.validatedModels.clear();
|
this.validatedModels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
volatile boolean initialized;
|
||||||
|
|
||||||
private void lazyInit() {
|
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) {
|
synchronized (this) {
|
||||||
if (emf == null) {
|
if (emf == null) {
|
||||||
this.emf = createEntityManagerFactory();
|
this.emf = createEntityManagerFactory();
|
||||||
|
}
|
||||||
|
if (!initialized) {
|
||||||
JpaMapUtils.addSpecificNamedQueries(emf);
|
JpaMapUtils.addSpecificNamedQueries(emf);
|
||||||
|
|
||||||
// consistency check for transaction handling, as this would lead to data-inconsistencies as changes wouldn't commit when expected
|
// consistency check for transaction handling, as this would lead to data-inconsistencies as changes wouldn't commit when expected
|
||||||
|
@ -353,12 +363,16 @@ public class JpaMapStorageProviderFactory implements
|
||||||
|
|
||||||
// consistency check for auto-commit, as this would lead to data-inconsistencies as changes wouldn't roll back when expected
|
// consistency check for auto-commit, as this would lead to data-inconsistencies as changes wouldn't roll back when expected
|
||||||
EntityManager em = getEntityManager();
|
EntityManager em = getEntityManager();
|
||||||
em.unwrap(SessionImpl.class).doWork(connection -> {
|
try {
|
||||||
if (connection.getAutoCommit()) {
|
em.unwrap(SessionImpl.class).doWork(connection -> {
|
||||||
throw new ModelException("The database connection must not use auto-commit. For Quarkus, auto-commit was off once JTA was enabled for the EntityManager.");
|
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.");
|
||||||
});
|
}
|
||||||
em.close();
|
});
|
||||||
|
} finally {
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
initialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue