Example usage for org.hibernate.cfg AvailableSettings USE_NEW_ID_GENERATOR_MAPPINGS

List of usage examples for org.hibernate.cfg AvailableSettings USE_NEW_ID_GENERATOR_MAPPINGS

Introduction

In this page you can find the example usage for org.hibernate.cfg AvailableSettings USE_NEW_ID_GENERATOR_MAPPINGS.

Prototype

String USE_NEW_ID_GENERATOR_MAPPINGS

To view the source code for org.hibernate.cfg AvailableSettings USE_NEW_ID_GENERATOR_MAPPINGS.

Click Source Link

Document

Setting which indicates whether or not the new org.hibernate.id.IdentifierGenerator are used for AUTO, TABLE and SEQUENCE.

Usage

From source file:com.astonish.dropwizard.routing.hibernate.RoutingSessionFactoryFactory.java

License:Apache License

/**
 * Builds a {@link SessionFactory}//  www . j  a v a 2s  .c o  m
 * @param bundle
 *            the bundle
 * @param dbConfig
 *            the dbconfig
 * @param connectionProvider
 *            the connection provider
 * @param properties
 *            the hibernate properties
 * @param entities
 *            the persistent entities
 * @return {@link SessionFactory}
 */
private SessionFactory buildSessionFactory(RoutingHibernateBundle<?> bundle, DataSourceFactory dbConfig,
        ConnectionProvider connectionProvider, Map<String, String> properties, List<Class<?>> entities) {
    final Configuration configuration = new Configuration();
    configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
    configuration.setProperty(AvailableSettings.USE_SQL_COMMENTS,
            Boolean.toString(dbConfig.isAutoCommentsEnabled()));
    configuration.setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, "true");
    configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
    configuration.setProperty(AvailableSettings.USE_REFLECTION_OPTIMIZER, "true");
    configuration.setProperty(AvailableSettings.ORDER_UPDATES, "true");
    configuration.setProperty(AvailableSettings.ORDER_INSERTS, "true");
    configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
    configuration.setProperty("jadira.usertype.autoRegisterUserTypes", "true");
    for (Map.Entry<String, String> property : properties.entrySet()) {
        configuration.setProperty(property.getKey(), property.getValue());
    }

    addAnnotatedClasses(configuration, entities);
    bundle.configure(configuration);

    final ServiceRegistry registry = new StandardServiceRegistryBuilder()
            .addService(ConnectionProvider.class, connectionProvider).applySettings(properties).build();

    return configuration.buildSessionFactory(registry);
}

From source file:com.yahoo.elide.contrib.dropwizard.elide.SessionFactoryFactory.java

License:Apache License

private SessionFactory buildSessionFactory(ElideBundle<?> bundle, PooledDataSourceFactory dbConfig,
        ConnectionProvider connectionProvider, Map<String, String> properties, List<Class<?>> entities) {
    final Configuration configuration = new Configuration();
    configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed");
    configuration.setProperty(AvailableSettings.USE_SQL_COMMENTS,
            Boolean.toString(dbConfig.isAutoCommentsEnabled()));
    configuration.setProperty(AvailableSettings.USE_GET_GENERATED_KEYS, "true");
    configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
    configuration.setProperty(AvailableSettings.USE_REFLECTION_OPTIMIZER, "true");
    configuration.setProperty(AvailableSettings.ORDER_UPDATES, "true");
    configuration.setProperty(AvailableSettings.ORDER_INSERTS, "true");
    configuration.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
    configuration.setProperty("jadira.usertype.autoRegisterUserTypes", "true");
    for (Map.Entry<String, String> property : properties.entrySet()) {
        configuration.setProperty(property.getKey(), property.getValue());
    }/*w w w .  j a v  a 2s.c  om*/

    addAnnotatedClasses(configuration, entities);
    bundle.configure(configuration);

    final ServiceRegistry registry = new StandardServiceRegistryBuilder()
            .addService(ConnectionProvider.class, connectionProvider)
            .applySettings(configuration.getProperties()).build();

    configure(configuration, registry);

    return configuration.buildSessionFactory(registry);
}

From source file:nz.geek.caffe.hdb.hibernate.demo.TestEmployee.java

License:Apache License

/**
 *///from ww w  .  ja  v a  2  s.c o m
@Before
public void setUp() {
    final DataSource ds = new DriverManagerDataSource(
            System.getProperty("jdbc.url", "jdbc:sap://localhost:30115"),
            System.getProperty("jdbc.user", "hibernate"), System.getProperty("jdbc.password", "hibernate"));

    final LocalSessionFactoryBuilder builder = new LocalSessionFactoryBuilder(ds);
    builder.setProperty(AvailableSettings.DIALECT,
            System.getProperty("hibernate.dialect", HANAColumnStoreDialect.class.getName()));
    builder.setProperty(AvailableSettings.HBM2DDL_AUTO, "create-drop");
    builder.setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");

    builder.addAnnotatedClass(Employee.class);

    this.sessionFactory = builder.buildSessionFactory();

    final HibernateTemplate ht = new HibernateTemplate();
    ht.setSessionFactory(this.sessionFactory);

    ht.afterPropertiesSet();

    this.template = ht;

    final HibernateTransactionManager txnMgr = new HibernateTransactionManager();
    txnMgr.setDataSource(ds);
    txnMgr.setSessionFactory(this.sessionFactory);
    txnMgr.afterPropertiesSet();

    this.transactionTemplate = new TransactionTemplate(txnMgr);
}

From source file:org.jahia.maven.hbm2ddl.JpaSchemaExportMojo.java

License:Open Source License

private Map<String, String> getHibernateProperties() {
    if (hibernateDialect != null && hibernateDialect.length() > 0) {
        Map<String, String> props = new HashMap<String, String>(2);
        props.put(AvailableSettings.DIALECT, hibernateDialect);
        props.put(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false");
        getLog().info("Using the following Hibernate dialect: " + hibernateDialect);
        return props;

    }//  www  . j  a  v a2 s. c  om
    return null;
}

From source file:org.jboss.additional.testsuite.jdkall.past.jpa.hibernate.secondlevelcache.SFSB.java

License:Open Source License

@TransactionAttribute(TransactionAttributeType.NEVER)
public void setupConfig() {
    // static {//from   w  ww  .  j  a v  a2s.c  om
    try {

        // prepare the configuration
        Configuration configuration = new Configuration()
                .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
        configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class);
        configuration.getProperties().put(AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jta");
        configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");
        // fetch the properties
        Properties properties = new Properties();
        configuration = configuration.configure("hibernate.cfg.xml");
        properties.putAll(configuration.getProperties());
        Environment.verifyProperties(properties);
        ConfigurationHelper.resolvePlaceHolders(properties);

        sessionFactory = configuration.buildSessionFactory();

    } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed
        ex.printStackTrace();
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:org.jboss.as.jpa.hibernate5.HibernatePersistenceProviderAdaptor.java

License:Apache License

@SuppressWarnings("deprecation")
@Override//from   www  .  java  2  s  .c om
public void addProviderProperties(Map properties, PersistenceUnitMetadata pu) {
    putPropertyIfAbsent(pu, properties, AvailableSettings.JPAQL_STRICT_COMPLIANCE, "true"); // JIPI-24 ignore jpql aliases case
    putPropertyIfAbsent(pu, properties, AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
    putPropertyIfAbsent(pu, properties, AvailableSettings.KEYWORD_AUTO_QUOTING_ENABLED, "false");
    putPropertyIfAbsent(pu, properties, AvailableSettings.IMPLICIT_NAMING_STRATEGY,
            NAMING_STRATEGY_JPA_COMPLIANT_IMPL);
    putPropertyIfAbsent(pu, properties, AvailableSettings.SCANNER, HibernateArchiveScanner.class);
    properties.put(AvailableSettings.APP_CLASSLOADER, pu.getClassLoader());
    putPropertyIfAbsent(pu, properties, AvailableSettings.JTA_PLATFORM,
            new JBossAppServerJtaPlatform(jtaManager));
    putPropertyIfAbsent(pu, properties, org.hibernate.ejb.AvailableSettings.ENTITY_MANAGER_FACTORY_NAME,
            pu.getScopedPersistenceUnitName());
    putPropertyIfAbsent(pu, properties, AvailableSettings.SESSION_FACTORY_NAME,
            pu.getScopedPersistenceUnitName());
    if (!pu.getProperties().containsKey(AvailableSettings.SESSION_FACTORY_NAME)) {
        putPropertyIfAbsent(pu, properties, AvailableSettings.SESSION_FACTORY_NAME_IS_JNDI, Boolean.FALSE);
    }
}

From source file:org.jboss.as.test.compat.jpa.hibernate.transformer.SFSBHibernateSessionFactory.java

License:Open Source License

public void setupConfig() {
    // static {//www . j  a  v  a  2s .  c  o  m
    try {

        // prepare the configuration
        Configuration configuration = new Configuration()
                .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
        configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");
        configuration.setProperty("hibernate.listeners.envers.autoRegister", "false");

        // fetch the properties
        Properties properties = new Properties();
        configuration = configuration.configure("hibernate.cfg.xml");
        properties.putAll(configuration.getProperties());

        Environment.verifyProperties(properties);
        ConfigurationHelper.resolvePlaceHolders(properties);

        sessionFactory = configuration.buildSessionFactory();
    } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed
        throw new RuntimeException("Could not setup config", ex);
    }

}

From source file:org.jboss.as.test.integration.hibernate.envers.SFSBHibernateEnversSessionFactory.java

License:Open Source License

public void setupConfig() {
    // static {//from  w w  w.j ava 2  s.c o  m
    try {

        //System.out.println("Current dir : " + (new File(".")).getCanonicalPath());

        // prepare the configuration
        Configuration configuration = new Configuration()
                .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
        configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");
        // fetch the properties
        Properties properties = new Properties();
        configuration = configuration.configure("hibernate.cfg.xml");
        properties.putAll(configuration.getProperties());
        Environment.verifyProperties(properties);
        ConfigurationHelper.resolvePlaceHolders(properties);

        sessionFactory = configuration.buildSessionFactory();
    } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }

}

From source file:org.jboss.as.test.integration.hibernate.naturalid.SFSBHibernateSFNaturalId.java

License:Open Source License

public void setupConfig() {
    // static {//from www  .ja  v a 2 s  . co  m
    try {

        // prepare the configuration
        Configuration configuration = new Configuration()
                .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
        configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");

        // configuration.configure("hibernate.cfg.xml");

        // fetch the properties
        Properties properties = new Properties();
        properties.putAll(configuration.getProperties());

        Environment.verifyProperties(properties);
        ConfigurationHelper.resolvePlaceHolders(properties);

        // build the serviceregistry
        final BootstrapServiceRegistryBuilder bootstrapbuilder = new BootstrapServiceRegistryBuilder();
        serviceRegistry = builder.build();

        // Create the SessionFactory from Configuration
        sessionFactory = configuration.configure("hibernate.cfg.xml").buildSessionFactory(serviceRegistry);

    } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        // ex.printStackTrace();
        throw new ExceptionInInitializerError(ex);
    }

}

From source file:org.jboss.as.test.integration.hibernate.secondlevelcache.SFSB.java

License:Open Source License

@TransactionAttribute(TransactionAttributeType.NEVER)
public void setupConfig() {
    // static {/*from   www  . ja v a  2 s  .  c  o m*/
    try {

        //System.out.println("setupConfig:  Current dir = " + (new File(".")).getCanonicalPath());

        // prepare the configuration
        Configuration configuration = new Configuration()
                .setProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
        configuration.getProperties().put(AvailableSettings.JTA_PLATFORM, JBossAppServerJtaPlatform.class);
        configuration.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        configuration.setProperty(Environment.DATASOURCE, "java:jboss/datasources/ExampleDS");
        // fetch the properties
        Properties properties = new Properties();
        configuration = configuration.configure("hibernate.cfg.xml");
        properties.putAll(configuration.getProperties());
        Environment.verifyProperties(properties);
        ConfigurationHelper.resolvePlaceHolders(properties);

        sessionFactory = configuration.buildSessionFactory();

    } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}