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();
}
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();
}
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();
}
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();
}
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());
}
Aggregations