List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:government.service.CitizenService.java
public void getAll() { ProvinceManager PM = new ProvinceManager(); CitizenManager CM = new CitizenManager(); SessionFactory SF = new Configuration().configure().buildSessionFactory(); Session session = SF.openSession();/*w w w . ja va 2 s . co m*/ CM.getAllCitizens(session); session.close(); SF.close(); }
From source file:government.service.ProvinceService.java
@Override public String addProvince(String name) { ProvinceManager PM = new ProvinceManager(); CitizenManager CM = new CitizenManager(); SessionFactory SF = new Configuration().configure().buildSessionFactory(); Session session = SF.openSession();//from www .j a v a 2 s. com Province province = new Province(name); PM.addProvince(province, session); session.close(); SF.close(); return "Entry has been saved Successfully !"; }
From source file:government.service.ProvinceService.java
@Override public String updateProvince(String provinceName, String newName) { ProvinceManager PM = new ProvinceManager(); CitizenManager CM = new CitizenManager(); SessionFactory SF = new Configuration().configure().buildSessionFactory(); Session session = SF.openSession();//ww w. j a va 2 s . c o m Province p = PM.getProvinceByName(provinceName, session); p.setName(newName); PM.updateProvince(p.getId(), p, session); session.close(); SF.close(); return "Entry has been updated Successfully !"; }
From source file:government.service.ProvinceService.java
@Override public String deleteProvince(String provinceName) { ProvinceManager PM = new ProvinceManager(); CitizenManager CM = new CitizenManager(); SessionFactory SF = new Configuration().configure().buildSessionFactory(); Session session = SF.openSession();//from w w w . j av a 2 s . c om Province p = PM.getProvinceByName(provinceName, session); PM.deleteProvince(p.getId(), session); session.close(); SF.close(); return "Entry has been deleted Successfully !"; }
From source file:government.service.ProvinceService.java
@Override public void getAll() { ProvinceManager PM = new ProvinceManager(); SessionFactory SF = new Configuration().configure().buildSessionFactory(); Session session = SF.openSession();// w w w . ja v a2 s . c om PM.getAllProvinces(session); session.close(); SF.close(); }
From source file:hibernatetest.HibernateTest.java
/** * @param args the command line arguments *//*from w w w. j av a 2s .c om*/ public static void main(String[] args) { User u = new User(109, "htrc"); User u1 = new User(10, "fbhtrc"); User u2 = new User(95, "kyuhtrc"); System.setProperty("hibernate.connection.url", "jdbc:postgresql://localhost:5432/hibernate"); SessionFactory sf = new Configuration().configure().buildSessionFactory(); Session s = sf.openSession(); s.beginTransaction(); s.save(u); s.save(u1); s.save(u2); //u=s.get(User.class,9); System.out.println("conn : " + System.getProperty("hibernate.connection.url")); s.getTransaction().commit(); s.close(); sf.close(); }
From source file:hibernatevalidaciones.Main.java
/** * @param args the command line arguments */// ww w . j av a 2 s. c o m public static void main(String[] args) { /*{ Profesor profesor = new Profesor("CA", null, null); SessionFactory sessionFactory = Utils.HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); try{ session.beginTransaction(); session.save(profesor); session.getTransaction().commit(); } catch (ConstraintViolationException ex){ session.getTransaction().rollback(); System.out.println("No se ha podido realizar la insercin"); for (ConstraintViolation e : ex.getConstraintViolations()) { System.out.println("En el campo " + e.getPropertyPath() + ": " + e.getMessage()); } } finally{ session.close(); sessionFactory.close(); } }*/ { Usuario usuario = new Usuario("pep", "Pep", "Garcia", "Garcia2", "123456789", "987654321"); SessionFactory sessionFactory = Utils.HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); try { session.beginTransaction(); session.save(usuario); session.getTransaction().commit(); } catch (ConstraintViolationException ex) { session.getTransaction().rollback(); System.out.println("No se ha podido realizar la insercin"); for (ConstraintViolation e : ex.getConstraintViolations()) { System.out.println("En el campo " + e.getPropertyPath() + ": " + e.getMessage()); } } finally { session.close(); sessionFactory.close(); } } }
From source file:hoteladmin.SearchPanelTmp.java
private int guestQuery(String searchOnField, String phrase) throws CorruptIndexException, InterruptedException, IOException, EmptyQueryException { SearchGuest searchGuestTmp = new SearchGuest(); SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); FullTextSession fullTextSession = Search.getFullTextSession(session); fullTextSession.createIndexer().startAndWait(); QueryBuilder b = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(SearchGuest.class).get(); Query luceneQuery = b.keyword().onField(searchOnField).boostedTo(1).matching(phrase).createQuery(); org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, SearchGuest.class); if (!fullTextQuery.list().isEmpty()) { Iterator it = fullTextQuery.list().iterator(); while (it.hasNext()) { searchGuestTmp = (SearchGuest) it.next(); System.out.println(searchGuestTmp.getId() + " " + searchGuestTmp.getName() + " " + searchGuestTmp.getLastName() + " " + searchGuestTmp.getStreet() + " " + searchGuestTmp.getCity() + " " + searchGuestTmp.getPhone()); }/*from w w w.j a va 2 s . c om*/ sessionFactory.close(); showResult.setSearch(searchGuestTmp); showResult.revalidate(); return searchGuestTmp.getId(); } else { sessionFactory.close(); if (!lastNameField.getText().isEmpty() || !phoneField.getText().isEmpty()) { MyDialog dialog = new MyDialog(point, "B?D", "Brak pasujcych wynikw"); } return -1; } }
From source file:hoteladmin.SearchPanelTmp.java
private int reservationsQuery(String searchOnField, int phrase) throws CorruptIndexException, InterruptedException, IOException, EmptyQueryException { List<SearchReservations> tmpList = new ArrayList<>(); SearchReservations searchResTmp = new SearchReservations(); SessionFactory sessionFactory2 = new Configuration().configure().buildSessionFactory(); Session session2 = sessionFactory2.openSession(); FullTextSession fullTextSession2 = Search.getFullTextSession(session2); fullTextSession2.createIndexer().startAndWait(); QueryBuilder b2 = fullTextSession2.getSearchFactory().buildQueryBuilder() .forEntity(SearchReservations.class).get(); Query luceneQuery2 = b2.keyword().onField(searchOnField).boostedTo(1).matching(phrase).createQuery(); org.hibernate.Query fullTextQuery2 = fullTextSession2.createFullTextQuery(luceneQuery2, SearchReservations.class); if (!fullTextQuery2.list().isEmpty()) { Iterator it = fullTextQuery2.list().iterator(); while (it.hasNext()) { searchResTmp = (SearchReservations) it.next(); tmpList.add(searchResTmp);//from w w w. j a v a 2 s.c o m } sessionFactory2.close(); ResShowResult.removeAll(); ResShowResult.revalidate(); ResShowResult.setSearch(tmpList); ResShowResult.revalidate(); return searchResTmp.getGuest(); } else { sessionFactory2.close(); if (!reservationField.getText().isEmpty()) { MyDialog dialog = new MyDialog(point, "B?D", "Brak pasujcych wynikw"); } return -1; } }
From source file:io.datalayer.hibernate.HibernateT4fMain.java
License:Apache License
/** * @param args// w ww. ja v a2s .co m */ public static void main(String... args) throws Exception { Thread databaseThread = new Thread(new DatabaseServerControlRunnable()); databaseThread.start(); /** Getting the Session Factory and session */ SessionFactory session = HibernateUtil.getSessionFactory(); Session sess = session.getCurrentSession(); /** Starting the Transaction */ Transaction tx = sess.beginTransaction(); /** Creating Pojo */ Employee pojo = new Employee(); pojo.setId(new Integer(5)); pojo.setName("XYZ"); /** Saving POJO */ sess.save(pojo); /** Commiting the changes */ tx.commit(); System.out.println("Record Inserted"); /** Closing Session */ session.close(); }