Search in sources :

Example 86 with Configuration

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

the class CmtSfStatefulBean method start.

@TransactionAttribute(TransactionAttributeType.NEVER)
public void start() {
    try {
        Configuration configuration = new Configuration();
        configuration = configuration.configure("hibernate.cfg.xml");
        configuration.addAnnotatedClass(WildFlyDdlEntity.class);
        sessionFactory = configuration.buildSessionFactory();
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 87 with Configuration

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

the class ArrayTypeContributorTest method constructAndConfigureConfiguration.

@Override
protected Configuration constructAndConfigureConfiguration() {
    Configuration configuration = super.constructAndConfigureConfiguration();
    configuration.registerTypeContributor((typeContributions, serviceRegistry) -> {
        typeContributions.contributeType(ArrayType.INSTANCE, new String[] { MyList.class.getName(), ArrayType.INSTANCE.getName() });
    });
    return configuration;
}
Also used : Configuration(org.hibernate.cfg.Configuration) MyList(org.hibernate.test.collection.custom.basic.MyList)

Example 88 with Configuration

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

the class OrmXmlParseTest method parseNamedAttributeNode.

@Test
@TestForIssue(jiraKey = "HHH-9247")
public void parseNamedAttributeNode() {
    final Configuration cfg = new Configuration();
    cfg.addURL(ConfigHelper.findAsResource("org/hibernate/test/annotations/entityGraph/orm.xml"));
    cfg.buildMappings();
}
Also used : Configuration(org.hibernate.cfg.Configuration) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 89 with Configuration

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

the class FetchProfileTest method testFetchProfileConfigured.

@Test
public void testFetchProfileConfigured() {
    Configuration config = new Configuration();
    config.addAnnotatedClass(Customer.class);
    config.addAnnotatedClass(Order.class);
    config.addAnnotatedClass(SupportTickets.class);
    config.addAnnotatedClass(Country.class);
    SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
    assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("customer-with-orders"));
    assertFalse("package info should not be parsed", sessionImpl.containsFetchProfileDefinition("package-profile-1"));
    sessionImpl.close();
}
Also used : Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test)

Example 90 with Configuration

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

the class FetchProfileTest method testXmlOverride.

@Test
public void testXmlOverride() {
    Configuration config = new Configuration();
    config.addAnnotatedClass(Customer5.class);
    config.addAnnotatedClass(Order.class);
    config.addAnnotatedClass(Country.class);
    InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("org/hibernate/test/annotations/fetchprofile/mappings.hbm.xml");
    config.addInputStream(is);
    SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
    assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("orders-profile"));
    sessionImpl.close();
    // now the same with no xml
    final MetadataSources metadataSources = new MetadataSources().addAnnotatedClass(Customer5.class).addAnnotatedClass(Order.class).addAnnotatedClass(Country.class);
    try {
        metadataSources.buildMetadata();
        fail();
    } catch (MappingException e) {
        log.trace("success");
    } finally {
        ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
        if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
            BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
        }
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) InputStream(java.io.InputStream) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MetadataSources(org.hibernate.boot.MetadataSources) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) MappingException(org.hibernate.MappingException) Test(org.junit.Test)

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