Search in sources :

Example 11 with Configuration

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

the class BasicIntegratorTest method testNoAudited.

/**
	 * Tests that nothing crazy happens if the hibernate-envers jar happens
	 * to be on the classpath but we have no audited entities
	 */
@Test
@TestForIssue(jiraKey = "HHH-9675")
public void testNoAudited() {
    new Configuration().buildSessionFactory().close();
    new Configuration().addAnnotatedClass(SimpleNonAuditedEntity.class).buildSessionFactory().close();
}
Also used : Configuration(org.hibernate.cfg.Configuration) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 12 with Configuration

use of org.hibernate.cfg.Configuration in project querydsl by querydsl.

the class HibernateTestRunner method start.

private void start() throws Exception {
    Configuration cfg = new Configuration();
    for (Class<?> cl : Domain.classes) {
        cfg.addAnnotatedClass(cl);
    }
    String mode = Mode.mode.get() + ".properties";
    isDerby = mode.contains("derby");
    if (isDerby) {
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
    }
    Properties props = new Properties();
    InputStream is = HibernateTestRunner.class.getResourceAsStream(mode);
    if (is == null) {
        throw new IllegalArgumentException("No configuration available at classpath:" + mode);
    }
    props.load(is);
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(props).build();
    cfg.setProperties(props);
    sessionFactory = cfg.buildSessionFactory(serviceRegistry);
    session = sessionFactory.openSession();
    session.beginTransaction();
}
Also used : Configuration(org.hibernate.cfg.Configuration) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) InputStream(java.io.InputStream) ServiceRegistry(org.hibernate.service.ServiceRegistry) Properties(java.util.Properties)

Example 13 with Configuration

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

the class ConfigurationTest method testIgnoringHbm.

@Test
public void testIgnoringHbm() throws Exception {
    Configuration cfg = new Configuration();
    cfg.configure("org/hibernate/test/annotations/hibernate.cfg.xml");
    cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
    cfg.setProperty(Configuration.ARTEFACT_PROCESSING_ORDER, "class");
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull(sf);
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();
    Query q;
    try {
        s.createQuery("from Boat").list();
        fail("Boat should not be mapped");
    } catch (IllegalArgumentException e) {
        assertTyping(QuerySyntaxException.class, e.getCause());
    //all good
    }
    q = s.createQuery("from Plane");
    assertEquals(0, q.list().size());
    tx.commit();
    s.close();
    sf.close();
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) Transaction(org.hibernate.Transaction) Query(org.hibernate.Query) QuerySyntaxException(org.hibernate.hql.internal.ast.QuerySyntaxException) Session(org.hibernate.Session) Test(org.junit.Test)

Example 14 with Configuration

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

the class ConfigurationTest method testPrecedenceHbm.

@Test
public void testPrecedenceHbm() throws Exception {
    Configuration cfg = new Configuration();
    cfg.configure("org/hibernate/test/annotations/hibernate.cfg.xml");
    cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
    cfg.addAnnotatedClass(Boat.class);
    SessionFactory sf = cfg.buildSessionFactory();
    assertNotNull(sf);
    Session s = sf.openSession();
    s.getTransaction().begin();
    Boat boat = new Boat();
    boat.setSize(12);
    boat.setWeight(34);
    s.persist(boat);
    s.getTransaction().commit();
    s.clear();
    Transaction tx = s.beginTransaction();
    boat = (Boat) s.get(Boat.class, boat.getId());
    assertTrue("Annotation has precedence", 34 != boat.getWeight());
    s.delete(boat);
    //s.getTransaction().commit();
    tx.commit();
    s.close();
    sf.close();
}
Also used : SessionFactory(org.hibernate.SessionFactory) Configuration(org.hibernate.cfg.Configuration) Transaction(org.hibernate.Transaction) Session(org.hibernate.Session) Test(org.junit.Test)

Example 15 with Configuration

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

the class ServiceRegistryClosingCascadeTest method testSessionFactoryClosing.

@Test
public void testSessionFactoryClosing() {
    BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
    StandardServiceRegistry sr = new StandardServiceRegistryBuilder(bsr).build();
    assertTrue(((BootstrapServiceRegistryImpl) bsr).isActive());
    Configuration config = new Configuration();
    SessionFactory sf = config.buildSessionFactory(sr);
    sf.close();
    assertFalse(((BootstrapServiceRegistryImpl) bsr).isActive());
}
Also used : SessionFactory(org.hibernate.SessionFactory) BootstrapServiceRegistryBuilder(org.hibernate.boot.registry.BootstrapServiceRegistryBuilder) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) Configuration(org.hibernate.cfg.Configuration) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

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