Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeffsheets/aec3e94870ef903ce7efe33e00563d3c to your computer and use it in GitHub Desktop.
Save jeffsheets/aec3e94870ef903ce7efe33e00563d3c to your computer and use it in GitHub Desktop.
Use JPA 2.1 and Hibernate 4.3.11 on Websphere 8.5.5.x
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());
}
}
@jeffsheets
Copy link
Author

@Prithal, sorry but I haven't done spring xml config in a long time. I'm not sure exactly, but somehow you would need to run the register() method in a PostConstruct, and have the config depend on hibernatePersistenceProviderResolver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment