Search in sources :

Example 21 with Configuration

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

the class EmbeddableIntegratorTest method testWithoutIntegrator.

/**
	 * Throws a mapping exception because DollarValue is not mapped
	 */
@Test
public void testWithoutIntegrator() {
    SessionFactory sf = new Configuration().addAnnotatedClass(Investor.class).setProperty("hibernate.hbm2ddl.auto", "create-drop").buildSessionFactory();
    try {
        Session sess = sf.openSession();
        try {
            sess.getTransaction().begin();
            Investor myInv = getInvestor();
            myInv.setId(1L);
            sess.save(myInv);
            sess.flush();
            fail("A JDBCException expected");
            sess.clear();
            Investor inv = (Investor) sess.get(Investor.class, 1L);
            assertEquals(new BigDecimal("100"), inv.getInvestments().get(0).getAmount().getAmount());
        } catch (PersistenceException e) {
            assertTyping(JDBCException.class, e.getCause());
            sess.getTransaction().rollback();
        }
        sess.close();
    } finally {
        sf.close();
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) JDBCException(org.hibernate.JDBCException) PersistenceException(javax.persistence.PersistenceException) BigDecimal(java.math.BigDecimal) Session(org.hibernate.Session) Test(org.junit.Test)

Example 22 with Configuration

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

the class BasicHibernateAnnotationsTest method testTypeDefWithoutNameAndDefaultForTypeAttributes.

@Test
public void testTypeDefWithoutNameAndDefaultForTypeAttributes() {
    SessionFactory sf = null;
    StandardServiceRegistryImpl ssr = null;
    try {
        Configuration config = new Configuration();
        config.addAnnotatedClass(LocalContactDetails.class);
        ssr = ServiceRegistryBuilder.buildServiceRegistry(config.getProperties());
        sf = config.buildSessionFactory(ssr);
        fail("Did not throw expected exception");
    } catch (AnnotationException ex) {
        assertEquals("Either name or defaultForType (or both) attribute should be set in TypeDef having typeClass org.hibernate.test.annotations.entity.PhoneNumberType", ex.getMessage());
    } finally {
        if (ssr != null) {
            ssr.destroy();
        }
        if (sf != null) {
            sf.close();
        }
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) AnnotationException(org.hibernate.AnnotationException) StandardServiceRegistryImpl(org.hibernate.boot.registry.internal.StandardServiceRegistryImpl) Test(org.junit.Test)

Example 23 with Configuration

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

the class AbstractBulkCompositeIdTest method constructConfiguration.

@Override
protected Configuration constructConfiguration() {
    Configuration configuration = super.constructConfiguration();
    configuration.setProperty(AvailableSettings.HQL_BULK_ID_STRATEGY, getMultiTableBulkIdStrategyClass().getName());
    return configuration;
}
Also used : Configuration(org.hibernate.cfg.Configuration)

Example 24 with Configuration

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

the class LazyInCacheTestTask method prepare.

public void prepare() {
    Configuration cfg = new Configuration();
    cfg.setProperty(Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true");
    cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
    prepare(cfg);
}
Also used : Configuration(org.hibernate.cfg.Configuration)

Example 25 with Configuration

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

the class SimpleLazyGroupUpdateTestTask method prepare.

@Override
public void prepare() {
    Configuration cfg = new Configuration();
    cfg.setProperty(Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true");
    cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
    super.prepare(cfg);
    Session s = getFactory().openSession();
    s.beginTransaction();
    s.save(new TestEntity(1, "entity 1", "blah", REALLY_BIG_STRING));
    s.getTransaction().commit();
    s.close();
}
Also used : Configuration(org.hibernate.cfg.Configuration) Session(org.hibernate.Session)

Aggregations

Configuration (org.hibernate.cfg.Configuration)179 Test (org.junit.Test)66 Session (org.hibernate.Session)37 SessionFactory (org.hibernate.SessionFactory)34 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)27 BeforeClass (org.junit.BeforeClass)19 Before (org.junit.Before)18 ServiceRegistry (org.hibernate.service.ServiceRegistry)14 File (java.io.File)13 Properties (java.util.Properties)11 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)9 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)8 HibernateException (org.hibernate.HibernateException)7 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