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 ServiceRegistryBuilder() .applySettings(props) .build(); cfg.setProperties(props); sessionFactory = cfg.buildSessionFactory(serviceRegistry); session = sessionFactory.openSession(); session.beginTransaction(); }