SHARE
TWEET

HibernatePersistenceProviderResolver

giancarloparma Oct 13th, 2017 (edited) 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Collections;
  2. import java.util.List;
  3.  
  4. import javax.persistence.spi.PersistenceProvider;
  5. import javax.persistence.spi.PersistenceProviderResolver;
  6. import javax.persistence.spi.PersistenceProviderResolverHolder;
  7.  
  8. import org.hibernate.jpa.HibernatePersistenceProvider;
  9.  
  10. public class HibernatePersistenceProviderResolver implements PersistenceProviderResolver {
  11.    
  12.     private volatile PersistenceProvider persistenceProvider = new HibernatePersistenceProvider();
  13.    
  14.     @Override
  15.     public List<PersistenceProvider> getPersistenceProviders() {
  16.         return Collections.singletonList(persistenceProvider);
  17.     }
  18.  
  19.     @Override
  20.     public void clearCachedProviders() {
  21.         persistenceProvider = new HibernatePersistenceProvider();
  22.     }
  23.    
  24.     public static void register() {
  25.         PersistenceProviderResolverHolder.setPersistenceProviderResolver(new HibernatePersistenceProviderResolver());
  26.     }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top