use of org.hibernate.cfg.Configuration in project onebusaway-gtfs-modules by OneBusAway.
the class HibernateGtfsRelationalImplBartTest method setup.
@BeforeClass
public static void setup() throws IOException {
Configuration config = new Configuration();
config = config.configure("org/onebusaway/gtfs/hibernate-configuration.xml");
_sessionFactory = config.buildSessionFactory();
_dao = new HibernateGtfsRelationalDaoImpl(_sessionFactory);
GtfsReader reader = new GtfsReader();
reader.setInputLocation(new File("src/test/resources/org/onebusaway/gtfs/bart.zip"));
reader.setEntityStore(_dao);
reader.setDefaultAgencyId(_agencyId);
reader.run();
}
use of org.hibernate.cfg.Configuration in project yyl_example by Relucent.
the class HibernateTest method main.
public static void main(String[] args) {
Configuration configuration = new Configuration().configure("/yyl/example/demo/hibernate/config/hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = null;
Session session = null;
try {
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
test1(sessionFactory);
test2(sessionFactory);
test3(sessionFactory);
} finally {
closeQuietly(session);
closeQuietly(sessionFactory);
}
}
use of org.hibernate.cfg.Configuration in project ACS by ACS-Community.
the class HibernateUtil method setConfiguration.
/**
* Use default configuration and add properties from Properties.
* Build session factory from combined configuration.
* @param config
*/
public void setConfiguration(Properties extraProperties) {
try {
Configuration config = new Configuration();
config.configure(getConfigurationFileName());
config.addProperties(extraProperties);
sessionFactory = config.buildSessionFactory();
configuration = config;
} catch (Throwable ex) {
// We have to catch Throwable, otherwise we will miss
// NoClassDefFoundError and other subclasses of Error
logger.log(Level.SEVERE, "Building SessionFactory failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}
use of org.hibernate.cfg.Configuration in project ACS by ACS-Community.
the class TestCase method buildSessionFactory.
protected void buildSessionFactory(Class<?>[] classes, String[] packages, String[] xmlFiles) throws Exception {
if (getSessions() != null)
getSessions().close();
try {
setCfg(new Configuration());
configure(cfg);
if (recreateSchema()) {
cfg.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
}
for (int i = 0; i < packages.length; i++) {
getCfg().addPackage(packages[i]);
}
for (int i = 0; i < classes.length; i++) {
getCfg().addAnnotatedClass(classes[i]);
}
for (int i = 0; i < xmlFiles.length; i++) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlFiles[i]);
getCfg().addInputStream(is);
}
// setDialect(Dialect.getDialect());
setSessions(getCfg().buildSessionFactory());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.
the class BaseCoreFunctionalTestCase method buildConfiguration.
protected Configuration buildConfiguration() {
Configuration cfg = constructAndConfigureConfiguration();
afterConstructAndConfigureConfiguration(cfg);
return cfg;
}
Aggregations