Search in sources :

Example 26 with Configuration

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

the class BatchVersionedDataConfigTest method setUp.

@Before
public void setUp() {
    cfg = new Configuration();
    // HHH-10290 ignore environment property hibernate.jdbc.batch_versioned_data
    if (cfg.getProperties().getProperty(AvailableSettings.BATCH_VERSIONED_DATA) != null) {
        cfg.getProperties().remove(AvailableSettings.BATCH_VERSIONED_DATA);
        cfg.getStandardServiceRegistryBuilder().getSettings().remove(AvailableSettings.BATCH_VERSIONED_DATA);
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) Before(org.junit.Before)

Example 27 with Configuration

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

the class CacheConfigurationTest method testCacheConfiguration.

@Test
public void testCacheConfiguration() throws Exception {
    // we only care if the SF builds successfully.
    Configuration cfg = new Configuration().configure(CFG_XML);
    cfg.buildSessionFactory().close();
}
Also used : Configuration(org.hibernate.cfg.Configuration) Test(org.junit.Test)

Example 28 with Configuration

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

the class AttributeConverterTest method testErrorInstantiatingConverterClass.

@Test
public void testErrorInstantiatingConverterClass() {
    Configuration cfg = new Configuration();
    try {
        cfg.addAttributeConverter(BlowsUpConverter.class);
        fail("expecting an exception");
    } catch (AnnotationException e) {
        assertNotNull(e.getCause());
        assertTyping(BlewUpException.class, e.getCause());
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) AnnotationException(org.hibernate.AnnotationException) Test(org.junit.Test)

Example 29 with Configuration

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

the class AttributeConverterTest method testBasicUsage.

@Test
public void testBasicUsage() {
    Configuration cfg = new Configuration();
    cfg.addAttributeConverter(IntegerToVarcharConverter.class, false);
    cfg.addAnnotatedClass(Tester4.class);
    cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "create-drop");
    cfg.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
    SessionFactory sf = cfg.buildSessionFactory();
    try {
        Session session = sf.openSession();
        session.beginTransaction();
        session.save(new Tester4(1L, "steve", 200));
        session.getTransaction().commit();
        session.close();
        sf.getStatistics().clear();
        session = sf.openSession();
        session.beginTransaction();
        session.get(Tester4.class, 1L);
        session.getTransaction().commit();
        session.close();
        assertEquals(0, sf.getStatistics().getEntityUpdateCount());
        session = sf.openSession();
        session.beginTransaction();
        Tester4 t4 = (Tester4) session.get(Tester4.class, 1L);
        t4.code = 300;
        session.getTransaction().commit();
        session.close();
        session = sf.openSession();
        session.beginTransaction();
        t4 = (Tester4) session.get(Tester4.class, 1L);
        assertEquals(300, t4.code.longValue());
        session.delete(t4);
        session.getTransaction().commit();
        session.close();
    } finally {
        sf.close();
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) Session(org.hibernate.Session) Test(org.junit.Test)

Example 30 with Configuration

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

the class LoadPlanStructureAssertionTest method testJoinedOneToOne.

@Test
public void testJoinedOneToOne() {
    // tests the mappings defined in org.hibernate.test.onetoone.joined.JoinedSubclassOneToOneTest
    Configuration cfg = new Configuration();
    cfg.addResource("org/hibernate/test/onetoone/joined/Person.hbm.xml");
    SessionFactoryImplementor sf = (SessionFactoryImplementor) cfg.buildSessionFactory();
    try {
        //			doCompare( sf, (OuterJoinLoadable) sf.getClassMetadata( org.hibernate.test.onetoone.joined.Person.class ) );
        doCompare(sf, (OuterJoinLoadable) sf.getClassMetadata(org.hibernate.test.onetoone.joined.Entity.class));
    //			doCompare( sf, (OuterJoinLoadable) sf.getClassMetadata( org.hibernate.test.onetoone.joined.Address.class ) );
    } finally {
        sf.close();
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test) EncapsulatedCompositeIdResultSetProcessorTest(org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)

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