Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package be.condorcet.projetpharmacie;
- import java.util.Properties;
- import org.hibernate.SessionFactory;
- /**
- * Hibernate Utility class with a convenient method to get Session Factory
- * object.
- *
- * @author Michel
- */
- public class NewHibernateUtil {
- private static final SessionFactory sessionFactory;
- static {
- try {
- String url = System.getenv().get("JDBC_DATABASE_URL");
- String username = System.getenv("JDBC_DATABASE_USERNAME");
- String password = System.getenv("JDBC_DATABASE_PASSWORD");
- Properties prop = new Properties();
- //provide the required properties
- prop.setProperty("hibernate.connection.url", url);
- prop.setProperty("hibernate.connection.username", username);
- prop.setProperty("hibernate.connection.password", password);
- prop.setProperty("dialect", "org.hibernate.dialect.PostgreSQLDialect");
- prop.setProperty("hibernate.query.factory_class", "org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory");
- prop.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver");
- //create a configuration
- org.hibernate.cfg.Configuration config = new org.hibernate.cfg.Configuration();
- //provide all properties to this configuration
- config.setProperties(prop);
- //add classes which are mapped to database tables.
- config.addResource("be/condorcet/projetpharmacie/ApiInfo.hbm.xml");
- config.addResource("be/condorcet/projetpharmacie/ApiMedecin.hbm.xml");
- config.addResource("be/condorcet/projetpharmacie/ApiMedicament.hbm.xml");
- config.addResource("be/condorcet/projetpharmacie/ApiPatient.hbm.xml");
- config.addResource("be/condorcet/projetpharmacie/ApiPrescription.hbm.xml");
- sessionFactory = config.buildSessionFactory();
- } catch (Throwable ex) {
- throw new ExceptionInInitializerError(ex);
- }
- }
- public static SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement