Forked from jeffsheets/HibernatePersistenceProviderResolver.java
Last active
July 21, 2020 17:45
-
-
Save Qleoz12/df32596c51e5f305dd3f0c0153cb7eea to your computer and use it in GitHub Desktop.
Use JPA 2.1 and Hibernate 4.3.11 on Websphere 8.5.5.x FIX Validate Using
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