From 7146435a429bc6e9e834163b500e7defccfbc846 Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Thu, 1 Aug 2013 21:36:58 -0400 Subject: [PATCH] HHH-8406 - fix for EntityManagerFactoryRegistry not being thread safe --- .../jpa/internal/EntityManagerFactoryRegistry.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryRegistry.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryRegistry.java index c371e6b660..58b49c615e 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryRegistry.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/EntityManagerFactoryRegistry.java @@ -139,10 +139,11 @@ public class EntityManagerFactoryRegistry { if (entityManagerFactorySet == null) { throw new HibernateException( "registry does not contain entity manager factory: " + name); } - - if (entityManagerFactorySet.size() > 1) { - throw new HibernateException( "registry contains more than one (" + entityManagerFactorySet.size()+ ") entity manager factories: " + name); + synchronized (entityManagerFactorySet) { + if (entityManagerFactorySet.size() > 1) { + throw new HibernateException( "registry contains more than one (" + entityManagerFactorySet.size()+ ") entity manager factories: " + name); + } + return entityManagerFactorySet.iterator().next(); } - return entityManagerFactorySet.iterator().next(); } }