List of usage examples for org.hibernate.cfg Configuration Configuration
public Configuration()
From source file:ch.bbw.siegrist.hotel.persitance.JPAHibernateDB.java
public JPAHibernateDB() { Configuration configuration = new Configuration(); configuration.configure("hibernate.cfg.xml"); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder() .applySettings(configuration.getProperties()); SessionFactory factory = configuration.buildSessionFactory(ssrb.build()); session = factory.openSession(); }// w w w. j a v a2 s . c o m
From source file:ch.icclab.cyclops.persistence.HibernateConfiguration.java
License:Open Source License
public static Configuration createConfiguration(HibernateCredentials credentials) { Configuration conf = new Configuration(); // add mandatory hibernate classes conf.addAnnotatedClass(LatestPullORM.class); conf.addAnnotatedClass(CumulativeMeterUsage.class); // now set properties conf.setProperty("hibernate.connection.driver_class", credentials.getHibernateDriver()) .setProperty("hibernate.connection.url", credentials.getHibernateURL()) .setProperty("hibernate.connection.username", credentials.getHibernateUsername()) .setProperty("hibernate.connection.password", credentials.getHibernatePassword()) .setProperty("hibernate.dialect", credentials.getHibernateDialect()) .setProperty("hibernate.hbm2ddl.auto", "update").setProperty("show_sql", "false"); return conf;// ww w.ja va 2 s . co m }
From source file:ch.qos.logback.audit.persistent.Persistor.java
License:Open Source License
static public Configuration createConfiguration() { final Configuration cfg = new Configuration(); // Configure Hibernate mappings,this will look for the "hbm.xml" resources. // In alphabetical order: cfg.addClass(AuditEvent.class); return cfg;//from w ww . ja v a 2 s . c o m }
From source file:cit360.ManageEmployee.java
public static void main(String[] args) { try {// w w w . j av a2 s . co m factory = new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { System.err.println("Failed to create sessionFactory object." + ex); throw new ExceptionInInitializerError(ex); } ManageEmployee ME = new ManageEmployee(); /* Add few employee records in database */ Integer empID1 = ME.addEmployee("Zara", "Ali", 1000); Integer empID2 = ME.addEmployee("Daisy", "Das", 5000); Integer empID3 = ME.addEmployee("John", "Paul", 10000); /* List down all the employees */ ME.listEmployees(); /* Update employee's records */ ME.updateEmployee(empID1, 5000); /* Delete an employee from the database */ ME.deleteEmployee(empID2); /* List down new list of the employees */ ME.listEmployees(); }
From source file:City.City.java
/** * @param args the command line arguments *//*from w ww . j a v a 2 s . co m*/ public static void main(String[] args) { // TODO code application logic here //creating configuration object //Configuration cfg=new Configuration(); //cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file //creating seession factory object //ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()). build(); //SessionFactory factory=cfg.buildSessionFactory(serviceRegistry); SessionFactory factory = new Configuration().configure().buildSessionFactory(); //creating session object String csvFile = "/Users/test/desktop/SC labs/geo.csv"; String line = ""; String cvsSplitBy = ","; try { BufferedReader br = new BufferedReader(new FileReader(csvFile)); br.readLine(); br.readLine(); //int count=1; while ((line = br.readLine()) != null) { Session session = factory.openSession(); //creating transaction object // use comma as separator String[] country = line.split(cvsSplitBy); //System.out.println(line); Transaction t = session.beginTransaction(); perCity c1 = new perCity(); c1.setId(Integer.valueOf(country[0])); // setting the value of id c1.setLat(Double.valueOf(country[5])); // setting the value of Latitude c1.setLon(Double.valueOf(country[6])); // setting the value of Longitude c1.setCountry(country[1]); // Srtting the value of Country code session.persist(c1);//persisting the object t.commit();//transaction is commited session.close(); // Closing the session after } } catch (IOException e) { e.printStackTrace(); } }
From source file:ClasseDao.ItemvendaDao.java
public java.util.List listarItens() { try {/* ww w . j a 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("from ItemVenda").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao preencher tabela" + e); } return null; }
From source file:ClasseDao.PagamentoDao.java
public java.util.List listarTodas() { try {/*from ww w . j a v a2 s .com*/ SessionFactory tp = new Configuration().configure().buildSessionFactory(); sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("from PagamentoEmprestimo").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao preencher tabela" + e); } return null; }
From source file:ClasseDao.PerfilDao.java
public java.util.List listarTodos() { try {// w ww .j a va2 s . c o m SessionFactory tp = new Configuration().configure().buildSessionFactory(); Session sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("from Perfil").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao preencher tabela" + e); } return null; }
From source file:ClasseDao.PerfilDao.java
public java.util.List listarNomes() { try {/*from w w w.j a v a 2s .co m*/ SessionFactory tp = new Configuration().configure().buildSessionFactory(); Session sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("select perfilNome from Perfil ").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.ProdutoDao.java
public java.util.List listarTodos() { try {//from w ww . j ava 2 s .c o m SessionFactory tp = new Configuration().configure().buildSessionFactory(); Session sessao = tp.openSession(); java.util.List lista = new ArrayList(); lista = sessao.createQuery("from Produto").list(); sessao.close(); return lista; } catch (Exception e) { JOptionPane.showMessageDialog(null, "Erro ao preencher tabela" + e); } return null; }