Forked from jeffsheets/HibernatePersistenceProviderResolver.java
Created
June 15, 2018 22:02
-
-
Save jpukg/f4e7582989eff8fa6d30f15e965ef90c to your computer and use it in GitHub Desktop.
Use JPA 2.1 and Hibernate 4.3.11 on Websphere 8.5.5.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.hibernate.jpa.HibernatePersistenceProvider; | |
| import org.springframework.context.annotation.Configuration; | |
| import javax.annotation.PostConstruct; | |
| import javax.persistence.spi.PersistenceProvider; | |
| import javax.persistence.spi.PersistenceProviderResolver; | |
| import javax.persistence.spi.PersistenceProviderResolverHolder; | |
| import java.util.Collections; | |
| import java.util.List; | |
| /** | |
| * This allows to deploy upgraded JPA and Hibernate versions to Websphere 8.5.5.x servers. | |
| * Has been used successfully with JPA 2.1 and Hibernate 4.3.11 | |
| * | |
| * Mostly a copy of <a href="https://hibernate.atlassian.net/browse/JPA-4">https://hibernate.atlassian.net/browse/JPA-4</a> | |
| * Changes made to deploy in a Spring environment. | |
| * | |
| * To use: add a @DependsOn("hibernatePersistenceProviderResolver") annotation on a DatabaseConfig class | |
| */ | |
| @Configuration | |
| public class HibernatePersistenceProviderResolver implements PersistenceProviderResolver { | |
| private volatile PersistenceProvider persistenceProvider = new HibernatePersistenceProvider(); | |
| @Override | |
| public List<PersistenceProvider> getPersistenceProviders() { | |
| return Collections.singletonList(persistenceProvider); | |
| } | |
| @Override | |
| public void clearCachedProviders() { | |
| persistenceProvider = new HibernatePersistenceProvider(); | |
| } | |
| @PostConstruct | |
| public void register() { | |
| PersistenceProviderResolverHolder.setPersistenceProviderResolver(new HibernatePersistenceProviderResolver()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment