List of usage examples for org.hibernate SessionFactory close
void close() throws HibernateException;
From source file:stepbystep.StepByStepExample.java
License:Open Source License
private void modifyPilotInHibernate() { org.hibernate.cfg.Configuration cfg = new org.hibernate.cfg.Configuration() .configure(hibernateConfigurationFileName); System.out.println("Configuring Hibernate to listen to object update events"); ReplicationConfigurator.configure(cfg); SessionFactory sessionFactory = cfg.buildSessionFactory(); Session session = sessionFactory.openSession(); System.out.println("Installing the object update event listener"); ReplicationConfigurator.install(session, cfg); Transaction tx = session.beginTransaction(); System.out.println("Finding Pilot 'John' in Hibernate."); Pilot john = (Pilot) session.createCriteria(Pilot.class).add(Restrictions.eq("name", "John")).list().get(0); System.out.println("Changing points of Pilot 'John' to 142"); john.setPoints(142);//from w ww . j a v a2s . c o m session.flush(); tx.commit(); session.close(); sessionFactory.close(); System.out.println("Changes committed to Hibernate."); }
From source file:subelergiris.SubelerGiris.java
@Override public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("SubelerGiris.fxml")); Scene scene = new Scene(root); stage.setScene(scene);/*w ww .ja va2 s . c om*/ stage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { SessionFactory sf = NewHibernateUtil.getSessionFactory(); sf.close(); } }); stage.show(); }
From source file:subelergiris.YeniSubeController.java
private void subeyeDon() throws IOException { Parent root = FXMLLoader.load(getClass().getResource("SubelerGiris.fxml")); Scene scene = new Scene(root); Stage stage = new Stage(); stage.setScene(scene);/*from ww w. j av a 2s. c om*/ stage.show(); stage.setOnCloseRequest(new EventHandler<WindowEvent>() { @Override public void handle(WindowEvent event) { SessionFactory sf = NewHibernateUtil.getSessionFactory(); Session session = sf.openSession(); session.close(); sf.close(); } }); }
From source file:test.QueryHibernate.java
public static void main(String[] args) { SessionFactory sf = new Configuration().configure().buildSessionFactory(); Session s = sf.openSession();//from w w w . jav a 2s . c o m s.beginTransaction(); Session s1 = sf.openSession(); Session s2 = sf.openSession(); s1.beginTransaction(); s2.beginTransaction(); Product p1 = (Product) s1.get(Product.class, 29); System.out.println("?: " + p1.getPrice()); p1.setPrice(p1.getPrice() + 1000); Product p2 = (Product) s2.get(Product.class, 29); p2.setPrice(p2.getPrice() + 1000); s1.update(p1); s2.update(p2); s1.getTransaction().commit(); s2.getTransaction().commit(); Product p = (Product) s1.get(Product.class, 29); System.out.println("???: " + p.getPrice()); s1.close(); s2.close(); s.getTransaction().commit(); s.close(); sf.close(); }
From source file:xworker.db.hibernate.HibernateContext.java
License:Apache License
public static void initDbSessionFactory(String name) { try {//w w w. j a va2 s .c o m SessionFactory f = (SessionFactory) factorys.get(name); if (f != null) { f.close(); f = null; factorys.remove(name); } File configFile = new File(world.getPath() + "/work/hibernate/" + name + "/hibernate.cfg.xml"); //URL url = World.class.getResource("../../" + name + "/hibernate.cfg.xml"); //if(url == null){ if (!configFile.exists()) { log.warn("??hibenate" + configFile.getAbsolutePath()); } else { //Configuration c = new Configuration().configure(url); Configuration c = new Configuration().configure(configFile); f = c.buildSessionFactory(); factorys.put(name, f); } } catch (Exception e) { //log.error("get db session factory", e); if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new ActionException(e); } } }
From source file:xworker.db.hibernate.HibernateContext.java
License:Apache License
public static void closeDBSessionFactory(String name) { SessionFactory f = (SessionFactory) factorys.get(name); if (f != null) { f.close(); f = null;/* w ww .jav a2s .co m*/ factorys.remove(name); } }