Search in sources :

Example 91 with Configuration

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

the class FetchProfileTest method testPackageConfiguredFetchProfile.

@Test
public void testPackageConfiguredFetchProfile() {
    Configuration config = new Configuration();
    config.addAnnotatedClass(Customer.class);
    config.addAnnotatedClass(Order.class);
    config.addAnnotatedClass(SupportTickets.class);
    config.addAnnotatedClass(Country.class);
    config.addPackage(Customer.class.getPackage().getName());
    SessionFactoryImplementor sessionImpl = (SessionFactoryImplementor) config.buildSessionFactory(serviceRegistry);
    assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("package-profile-1"));
    assertTrue("fetch profile not parsed properly", sessionImpl.containsFetchProfileDefinition("package-profile-2"));
    sessionImpl.close();
}
Also used : Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test)

Example 92 with Configuration

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

the class MappedSuperclassTestTask 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, "false");
    super.prepare(cfg);
}
Also used : Configuration(org.hibernate.cfg.Configuration)

Example 93 with Configuration

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

the class LazyCollectionWithClearedSessionTestTask method prepare.

public void prepare() {
    Configuration cfg = new Configuration();
    cfg.setProperty(Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true");
    cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
    cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
    super.prepare(cfg);
    try (Session s = getFactory().openSession()) {
        s.beginTransaction();
        try {
            Store store = new Store(1).setName("Acme Super Outlet");
            s.persist(store);
            Product product = new Product("007").setName("widget").setDescription("FooBar");
            s.persist(product);
            store.addInventoryProduct(product).setQuantity(10L).setStorePrice(new BigDecimal(500));
            s.getTransaction().commit();
        } catch (Exception e) {
            if (s.getTransaction().isActive()) {
                s.getTransaction().rollback();
            }
            throw e;
        }
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) BigDecimal(java.math.BigDecimal) Session(org.hibernate.Session)

Example 94 with Configuration

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

the class LazyCollectionWithClosedSessionTestTask method prepare.

public void prepare() {
    Configuration cfg = new Configuration();
    cfg.setProperty(Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true");
    cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
    cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
    super.prepare(cfg);
    try (Session s = getFactory().openSession()) {
        s.beginTransaction();
        try {
            Store store = new Store(1).setName("Acme Super Outlet");
            s.persist(store);
            Product product = new Product("007").setName("widget").setDescription("FooBar");
            s.persist(product);
            store.addInventoryProduct(product).setQuantity(10L).setStorePrice(new BigDecimal(500));
            s.getTransaction().commit();
        } catch (Exception e) {
            if (s.getTransaction().isActive()) {
                s.getTransaction().rollback();
            }
            throw e;
        }
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) BigDecimal(java.math.BigDecimal) Session(org.hibernate.Session)

Example 95 with Configuration

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

the class LazyEntityLoadingWithClosedSessionTestTask method prepare.

public void prepare() {
    Configuration cfg = new Configuration();
    cfg.setProperty(Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true");
    cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
    cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
    super.prepare(cfg);
    try (Session s = getFactory().openSession()) {
        s.beginTransaction();
        try {
            Store store = new Store(1).setName("Acme Super Outlet");
            s.persist(store);
            Product product = new Product("007").setName("widget").setDescription("FooBar");
            s.persist(product);
            store.addInventoryProduct(product).setQuantity(10L).setStorePrice(new BigDecimal(500));
            s.getTransaction().commit();
        } catch (Exception e) {
            if (s.getTransaction().isActive()) {
                s.getTransaction().rollback();
            }
            throw e;
        }
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) BigDecimal(java.math.BigDecimal) Session(org.hibernate.Session)

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