Example usage for org.hibernate.jpa AvailableSettings IDENTIFIER_GENERATOR_STRATEGY_PROVIDER

List of usage examples for org.hibernate.jpa AvailableSettings IDENTIFIER_GENERATOR_STRATEGY_PROVIDER

Introduction

In this page you can find the example usage for org.hibernate.jpa AvailableSettings IDENTIFIER_GENERATOR_STRATEGY_PROVIDER.

Prototype

String IDENTIFIER_GENERATOR_STRATEGY_PROVIDER

To view the source code for org.hibernate.jpa AvailableSettings IDENTIFIER_GENERATOR_STRATEGY_PROVIDER.

Click Source Link

Document

IdentifierGeneratorStrategyProvider class name, the class must have a no-arg constructor

Usage

From source file:net.e6tech.elements.persist.hibernate.HibernateEntityManagerProvider.java

License:Apache License

@Override
public void initialize(Resources resources) {
    if (System.getProperty(Context.INITIAL_CONTEXT_FACTORY) == null) {
        InitialContextFactory.setDefault();
    }/*from ww  w .ja  va2 s  . co  m*/

    // Note: AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER is deprecated.
    // note: another way to do it is to subclass HibernatePersistenceProvider and override
    // getEntityManagerFactoryBuilder(PersistenceUnitDescriptor persistenceUnitDescriptor, Map integration, ClassLoader providedClassLoader)
    // to provide a builder (which subclasses EntityManagerFactoryBuilderImpl in order to hook in the strategies.
    if (identifierGenerators.size() > 0) {
        Map<String, Class<?>> strategies = new LinkedHashMap<>();
        for (Map.Entry<String, IdentifierGenerator> entry : identifierGenerators.entrySet()) {
            Class<IdentifierGenerator> cls = net.e6tech.elements.common.interceptor.Interceptor
                    .newPrototypeClass((Class<IdentifierGenerator>) entry.getValue().getClass(),
                            entry.getValue());
            strategies.put(entry.getKey(), cls);
        }

        getPersistenceProperties().put(AvailableSettings.IDENTIFIER_GENERATOR_STRATEGY_PROVIDER,
                (IdentifierGeneratorStrategyProvider) () -> strategies);
    }
    super.initialize(resources);
}