List of usage examples for org.hibernate.cfg Configuration buildSessionFactory
public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException
From source file:br.com.fabiose.book.utils.HibernateUtil.java
public static SessionFactory factory() { Configuration configuration = new Configuration().configure(); StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder(); serviceRegistryBuilder.applySettings(configuration.getProperties()); ServiceRegistry serviceRegistry = serviceRegistryBuilder.build(); return configuration.buildSessionFactory(serviceRegistry); }
From source file:br.com.mandado.util.HibernateUtil.java
/** * @return/*from w ww.jav a 2s. c om*/ */ private static SessionFactory buildSessionFactory() { try { // Cria um SessionFactory a partir do hibernate.cfg.xml Configuration configuration = new Configuration(); configuration.configure(); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); return sessionFactory; } catch (Exception ex) { // Exibe uma mensagem de erro System.err.println("Falha ao tentar criar o SessionFactory." + ex); throw new ExceptionInInitializerError(ex); } }
From source file:br.com.moises.util.HibernateUtil.java
private static SessionFactory buildSessionFactory() { try {/*from www.j a v a 2s .c o m*/ // Create the SessionFactory from hibernate.cfg.xml Configuration configuration = new Configuration(); configuration.configure(); ServiceRegistry serviveRegistre = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); sessionFactory = configuration.buildSessionFactory(serviveRegistre); return sessionFactory; } 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); } }
From source file:br.com.nfsconsultoria.nfsuporte.util.HibernateUtil.java
private static SessionFactory criarFabricaDeSesoes() { try {//from w ww . ja v a 2 s . co m Configuration configuration = new Configuration().configure(); ServiceRegistry registro = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); SessionFactory fabrica = configuration.buildSessionFactory(registro); return fabrica; } catch (Throwable ex) { System.err.println("A fabrica de sesses no pode ser criada. " + ex); throw new ExceptionInInitializerError(ex); } }
From source file:br.com.progolden.dneutils.HibernateSessionFactory.java
License:Apache License
public static SessionFactory getInstance() { if (HibernateSessionFactory.factory == null) { LOG.debug("Carregando Hibernate pelo arquivo: hibernate.cfg.xml"); Configuration config = new Configuration(); config.configure("hibernate.cfg.xml"); ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder() .applySettings(config.getProperties()); HibernateSessionFactory.factory = config .buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry()); }//from www .j a v a2 s .c om return HibernateSessionFactory.factory; }
From source file:br.com.progolden.dneutils.utils.DNEHibernateSessionFactory.java
License:Apache License
public DNEHibernateSessionFactory(String configFile) { if ((configFile == null) || (configFile.equals(""))) { LOG.info("Inicializando a DNE sem conexo com o banco de dados."); this.customFactory = null; } else {/*from w w w. j a v a 2 s. co m*/ try { LOG.debug("Carregando DNE no Hibernate pelo arquivo: " + configFile); Configuration config = new Configuration(); config.configure("dne.hibernate.mappings.xml").configure(configFile); ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder() .applySettings(config.getProperties()); this.customFactory = config.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry()); } catch (Exception ex) { LOG.error("Um erro ocorreu ao tentar estabelecer a conexo com a DNE pelo arquivo: " + configFile, ex); LOG.info("Inicializando a DNE sem conexo com o banco de dados devido erros."); this.customFactory = null; } } }
From source file:br.com.proj.tasker.util.HibernateUtil.java
public static SessionFactory createSessionFactory() { Configuration configuration = new Configuration(); configuration.configure();/*from w w w . j a v a 2 s.c o m*/ serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()) .buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); return sessionFactory; }
From source file:br.com.railsos.os.util.HibernateUtil.java
private static SessionFactory buildSessionFactory() { try {//from w ww .j a v a2 s. c om // Create the SessionFactory from hibernate.cfg.xml Configuration configuration = new Configuration(); configuration.configure(); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); SessionFactory Factory = configuration.buildSessionFactory(serviceRegistry); return Factory; } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("A fbrica de sesses no pode ser criada." + ex); throw new ExceptionInInitializerError(ex); } }
From source file:br.com.sgejs.database.ConexaoBanco.java
@Produces @ApplicationScoped/*from w ww .ja v a 2 s.c om*/ public SessionFactory ConexaoBanco() { if (this.factory == null) { Configuration configuration = new Configuration().configure(); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); this.factory = configuration.buildSessionFactory(serviceRegistry); } return this.factory; }
From source file:br.com.sicva.conexao.FabricaDeConexao.java
private static SessionFactory buildSessionFactory() { try {//from ww w . java 2 s . c o m Configuration configuracao = new Configuration().configure(); ServiceRegistry registro = new StandardServiceRegistryBuilder() .applySettings(configuracao.getProperties()).build(); SessionFactory fabrica = configuracao.buildSessionFactory(registro); return fabrica; } catch (Throwable ex) { System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } }