List of usage examples for org.hibernate.cfg Configuration Configuration
public Configuration()
From source file:ClasseDao.ProdutoDao.java
public java.util.List listarNomes() { try {/*from w ww.ja v a 2 s.c om*/ SessionFactory tp = new Configuration().configure().buildSessionFactory(); Session sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("select nomeProduto from Produto ").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao buscar o nome do Produto" + e); } return null; }
From source file:ClasseDao.RelatorioEntradaDao.java
public java.util.List listarTodos(Tipoproduto cli) { try {/* w w w .ja va 2s . c o m*/ SessionFactory tp = new Configuration().configure().buildSessionFactory(); sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("from RelatorioEntrada order by idRelatorioEntrada ").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao preencher tabela" + e); } return null; }
From source file:ClasseDao.UsuarioDao.java
public java.util.List listarTodos() { try {//from w ww . j av a2s .c o m SessionFactory tp = new Configuration().configure().buildSessionFactory(); sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("from Usuario").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao preencher tabela" + e); } return null; }
From source file:ClasseDao.UsuarioDao.java
public java.util.List listarNomes() { try {// w w w. java2s .c om SessionFactory tp = new Configuration().configure().buildSessionFactory(); Session sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("SELECT nomeUsuario from Usuario ").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao preencher tabela" + e); } return null; }
From source file:ClasseDao.VendaDao.java
public java.util.List listarTodas() { try {//from ww w. j a v a 2 s . c o m SessionFactory tp = new Configuration().configure().buildSessionFactory(); sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("from Venda").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao preencher tabela" + e); } return null; }
From source file:ClasseDao.VendaDao.java
public java.util.List listarNomes() { try {/*from w ww . j a v a 2s.c o m*/ SessionFactory tp = new Configuration().configure().buildSessionFactory(); Session sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("SELECT nomeCliente from Cliente ").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao preencher tabela" + e); } return null; }
From source file:cloudoutput.database.HibernateUtil.java
License:Open Source License
/** * Sets the active database./*ww w . j av a 2 s.c o m*/ * It changes the active database and builds a new session factory for it. * * @param aActiveDatabase the name of the file that contains the new database. * @see #activeDatabase * @since 1.0 */ public static void setActiveDatabase(String aActiveDatabase) { if (sessionFactory != null) sessionFactory.close(); activeDatabase = aActiveDatabase; Configuration cfg = new Configuration(); cfg.configure(); System.setProperty("hibernate.connection.driver_class", "org.sqlite.JDBC"); System.setProperty("hibernate.dialect", "cloudoutput.database.SQLiteDialect"); System.setProperty("hibernate.connection.url", "jdbc:sqlite:db/" + activeDatabase); cfg.setProperties(System.getProperties()); sessionFactory = cfg.buildSessionFactory(); }
From source file:cloudreports.database.HibernateUtil.java
License:Open Source License
/** * Sets the active database./*from ww w.j a v a2 s . c o m*/ * It changes the active database and builds a new session factory for it. * * @param aActiveDatabase the name of the file that contains the new database. * @see #activeDatabase * @since 1.0 */ public static void setActiveDatabase(String aActiveDatabase) { if (sessionFactory != null) sessionFactory.close(); activeDatabase = aActiveDatabase; Configuration cfg = new Configuration(); cfg.configure(); System.setProperty("hibernate.connection.driver_class", "org.sqlite.JDBC"); System.setProperty("hibernate.dialect", "cloudreports.database.SQLiteDialect"); System.setProperty("hibernate.connection.url", "jdbc:sqlite:db/" + activeDatabase); cfg.setProperties(System.getProperties()); sessionFactory = cfg.buildSessionFactory(); }
From source file:club.jmint.mifty.dao.Dao.java
License:Apache License
private static SessionFactory buildSessionFactory() { try {//from w ww . j a v a2 s.c om // Create the SessionFactory from hibernate.cfg.xml // return new Configuration().configure().buildSessionFactory( // new StandardServiceRegistryBuilder().build() ); // String udir = System.getProperty("user.dir"); // String fdir = udir + File.separator+"conf"+File.separator+"hibernate.cfg.xml"; Configuration cfg = new Configuration().configure(new File("conf/hibernate.cfg.xml")); StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() .applySettings(cfg.getProperties()).build(); SessionFactory sf = cfg.buildSessionFactory(serviceRegistry); CrossLog.logger.info("DAO SessionFactory initialized."); return sf; } catch (Throwable ex) { CrossLog.logger.error("DAO SessionFactory initialization failed."); throw new ExceptionInInitializerError(ex); } }
From source file:cn.fql.template.hibernate.HibernateTest.java
License:Open Source License
protected void setUp() throws Exception { Configuration config = new Configuration().configure(); SessionFactory sessionFactory = config.buildSessionFactory(); session = sessionFactory.openSession(); }