Search in sources :

Example 56 with Configuration

use of org.hibernate.cfg.Configuration in project wildfly by wildfly.

the class SFSBHibernate2LcacheStats method setupConfig.

@TransactionAttribute(TransactionAttributeType.NEVER)
public void setupConfig() {
    // static {
    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");
        // set property to enable statistics
        configuration.setProperty("hibernate.generate_statistics", "true");
        // fetch the properties
        Properties properties = new Properties();
        configuration = configuration.configure("hibernate.cfg.xml");
        properties.putAll(configuration.getProperties());
        Environment.verifyProperties(properties);
        ConfigurationHelper.resolvePlaceHolders(properties);
        // build the serviceregistry
        sessionFactory = configuration.buildSessionFactory();
    } catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        ex.printStackTrace();
        throw new ExceptionInInitializerError(ex);
    }
//System.out.println("setupConfig: done");
}
Also used : Configuration(org.hibernate.cfg.Configuration) Properties(java.util.Properties) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 57 with Configuration

use of org.hibernate.cfg.Configuration in project wildfly by wildfly.

the class SFSBHibernateSessionFactory method setupConfig.

public void setupConfig() {
    // static {
    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);
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) Properties(java.util.Properties)

Example 58 with Configuration

use of org.hibernate.cfg.Configuration in project wildfly by wildfly.

the class SFSBHibernateEnversSessionFactory method setupConfig.

public void setupConfig() {
    // static {
    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");
        // 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);
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) Properties(java.util.Properties)

Example 59 with Configuration

use of org.hibernate.cfg.Configuration in project API by ca-cwds.

the class ClientDaoIT method beforeClass.

@SuppressWarnings("javadoc")
@BeforeClass
public static void beforeClass() {
    sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
    clientDao = new ClientDao(sessionFactory);
}
Also used : Configuration(org.hibernate.cfg.Configuration) BeforeClass(org.junit.BeforeClass)

Example 60 with Configuration

use of org.hibernate.cfg.Configuration in project API by ca-cwds.

the class ClientUcDaoIT method setup.

/**
   * 
   */
@Override
@Before
public void setup() {
    sessionFactory = new Configuration().configure().buildSessionFactory();
    sessionFactory.getCurrentSession().beginTransaction();
    clientUcDao = new ClientUcDao(sessionFactory);
}
Also used : Configuration(org.hibernate.cfg.Configuration) Before(org.junit.Before)

Aggregations

Configuration (org.hibernate.cfg.Configuration)190 Test (org.junit.Test)66 Session (org.hibernate.Session)37 SessionFactory (org.hibernate.SessionFactory)35 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)27 Before (org.junit.Before)20 BeforeClass (org.junit.BeforeClass)20 File (java.io.File)18 ServiceRegistry (org.hibernate.service.ServiceRegistry)14 Properties (java.util.Properties)13 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)9 HibernateException (org.hibernate.HibernateException)8 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)8 MappingException (org.hibernate.MappingException)7 Transaction (org.hibernate.Transaction)7 URL (java.net.URL)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 TestForIssue (org.hibernate.testing.TestForIssue)6 EntityTuplizer (org.hibernate.tuple.entity.EntityTuplizer)6 BigDecimal (java.math.BigDecimal)5