Search in sources :

Example 51 with Configuration

use of org.hibernate.cfg.Configuration in project onebusaway-gtfs-modules by OneBusAway.

the class HibernateGtfsRelationalImplBartTest method setup.

@BeforeClass
public static void setup() throws IOException {
    Configuration config = new Configuration();
    config = config.configure("org/onebusaway/gtfs/hibernate-configuration.xml");
    _sessionFactory = config.buildSessionFactory();
    _dao = new HibernateGtfsRelationalDaoImpl(_sessionFactory);
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(new File("src/test/resources/org/onebusaway/gtfs/bart.zip"));
    reader.setEntityStore(_dao);
    reader.setDefaultAgencyId(_agencyId);
    reader.run();
}
Also used : GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) Configuration(org.hibernate.cfg.Configuration) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 52 with Configuration

use of org.hibernate.cfg.Configuration in project yyl_example by Relucent.

the class HibernateTest method main.

public static void main(String[] args) {
    Configuration configuration = new Configuration().configure("/yyl/example/demo/hibernate/config/hibernate.cfg.xml");
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    SessionFactory sessionFactory = null;
    Session session = null;
    try {
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        test1(sessionFactory);
        test2(sessionFactory);
        test3(sessionFactory);
    } finally {
        closeQuietly(session);
        closeQuietly(sessionFactory);
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ServiceRegistry(org.hibernate.service.ServiceRegistry) Session(org.hibernate.Session)

Example 53 with Configuration

use of org.hibernate.cfg.Configuration in project ACS by ACS-Community.

the class HibernateUtil method setConfiguration.

/**
	 * Use default configuration and add properties from Properties.
	 * Build session factory from combined configuration.
	 * @param config
	 */
public void setConfiguration(Properties extraProperties) {
    try {
        Configuration config = new Configuration();
        config.configure(getConfigurationFileName());
        config.addProperties(extraProperties);
        sessionFactory = config.buildSessionFactory();
        configuration = config;
    } catch (Throwable ex) {
        // We have to catch Throwable, otherwise we will miss
        // NoClassDefFoundError and other subclasses of Error
        logger.log(Level.SEVERE, "Building SessionFactory failed.", ex);
        throw new ExceptionInInitializerError(ex);
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration)

Example 54 with Configuration

use of org.hibernate.cfg.Configuration in project ACS by ACS-Community.

the class TestCase method buildSessionFactory.

protected void buildSessionFactory(Class<?>[] classes, String[] packages, String[] xmlFiles) throws Exception {
    if (getSessions() != null)
        getSessions().close();
    try {
        setCfg(new Configuration());
        configure(cfg);
        if (recreateSchema()) {
            cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
        }
        for (int i = 0; i < packages.length; i++) {
            getCfg().addPackage(packages[i]);
        }
        for (int i = 0; i < classes.length; i++) {
            getCfg().addAnnotatedClass(classes[i]);
        }
        for (int i = 0; i < xmlFiles.length; i++) {
            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFiles[i]);
            getCfg().addInputStream(is);
        }
        //	setDialect(Dialect.getDialect());
        setSessions(getCfg().buildSessionFactory());
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) InputStream(java.io.InputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) HibernateException(org.hibernate.HibernateException)

Example 55 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class BaseCoreFunctionalTestCase method buildConfiguration.

protected Configuration buildConfiguration() {
    Configuration cfg = constructAndConfigureConfiguration();
    afterConstructAndConfigureConfiguration(cfg);
    return cfg;
}
Also used : Configuration(org.hibernate.cfg.Configuration)

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