Skip to content

Commit

Permalink
ARTIF-760 Init DDL called several times by different threads
Browse files Browse the repository at this point in the history
  • Loading branch information
dvirgiln committed Oct 1, 2015
1 parent f1610c7 commit fc849cf
Showing 1 changed file with 5 additions and 1 deletion.
Expand Up @@ -64,6 +64,7 @@ public T execute() throws ArtificerException {
EntityManager entityManager = null;
try {
entityManager = entityManager();

entityManager.getTransaction().begin();

T rtn = doExecute(entityManager);
Expand Down Expand Up @@ -101,7 +102,7 @@ public T execute() throws ArtificerException {
protected abstract T doExecute(EntityManager entityManager) throws Exception;
}

private static EntityManager entityManager() throws Exception {
private synchronized static EntityManager entityManager() throws Exception {
if (entityManagerFactory == null) {
// Pass in all hibernate.* settings from artificer.properties
Map<String, Object> properties = ArtificerConfig.getConfigProperties("hibernate");
Expand Down Expand Up @@ -185,6 +186,9 @@ private static void initDDL(EntityManager entityManager, Map<String, Object> pro
try {
statement = connection.createStatement();
statement.executeUpdate(query + ";");
} catch (Exception e) {
System.out.println("Exception executing Query:" + query);
throw e;
} finally {
if (statement != null) {
statement.close();
Expand Down

0 comments on commit fc849cf

Please sign in to comment.