1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| public class HibernateConfiguration{
private static final SessionFactory sessionFactory = buildSessionFactory();
public static SessionFactory buildSessionFactory() {
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");
configuration.setProperty("hibernate.connection.url", "jdbc:mysql://localhost/MDB");
configuration.setProperty("hibernate.connection.username", "root");
configuration.setProperty("hibernate.connection.driver_class", "org.gjt.mm.mysql.Driver");
configuration.setProperty("hibernate.connection.password", "xxx");
configuration.setProperty("hibernate.current_session_context_class", "thread");
configuration.setProperty("hibernate.show_sql", "true");
configuration.addResource("com/oghmasys/nomad/mdblib/mappingxml/Transformation.hbm.xml");
configuration.addResource("com/oghmasys/nomad/mdblib/mappingxml/Timeref.hbm.xml");
configuration.addResource("com/oghmasys/nomad/mdblib/mappingxml/Libra.hbm.xml");
try {
return configuration.buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static void shutdown() {
// Close caches and connection pools
getSessionFactory().close();
}
} |
Partager