List of usage examples for org.hibernate SessionFactory openSession
Session openSession() throws HibernateException;
From source file:appHibernateSebastianLeonte.Main.java
public static void modificar() { SessionFactory session = SessionFactoryUtil.getSessionFactory(); Session s = session.openSession(); Transaction transaction = s.beginTransaction(); System.out.println("Modificando"); Vuelos vuelos = (Vuelos) s.load(Vuelos.class, (String) "AB-BY-4811"); vuelos.setProcedencia("Hola"); s.update(vuelos);//from w w w. j a v a 2s. c o m s.save(vuelos); transaction.commit(); s.close(); session.close(); }
From source file:appHibernateSebastianLeonte.Main.java
public static void consulta() { SessionFactory session = SessionFactoryUtil.getSessionFactory(); Session s = session.openSession(); Transaction transaction = s.beginTransaction(); System.out.println("Modificando"); Vuelos vuelo = new Vuelos(); Query q = s.createQuery("from Vuelos where Destino='BARCELONA' or Destino='MADRID'"); List<Vuelos> listaVuelo = q.list(); Iterator<Vuelos> iter = listaVuelo.iterator(); while (iter.hasNext()) { vuelo = (Vuelos) iter.next();// w ww . j ava2s . c o m System.out.println("PROCEDENCIA: " + vuelo.getProcedencia() + "\t"); System.out.println("DESTINO: " + vuelo.getDestino() + "\t"); System.out.println("HORA DE SALIDA: " + vuelo.getHoraSalida()); } s.close(); session.close(); }
From source file:at.molindo.esi4j.module.hibernate.HibernateEntityResolver.java
License:Apache License
protected Session getNewSession(SessionFactory factory) { return factory.openSession(); }
From source file:at.molindo.esi4j.module.hibernate.HibernateRebuildSession.java
License:Apache License
public HibernateRebuildSession(Class<?> type, SessionFactory sessionFactory, HibernateModule module, ScrollingSession scrollingSession) { if (type == null) { throw new NullPointerException("type"); }/* ww w . ja v a 2 s. c o m*/ if (sessionFactory == null) { throw new NullPointerException("sessionFactory"); } if (module == null) { throw new NullPointerException("module"); } _type = type; _module = module; _scrollingSession = scrollingSession; _session = sessionFactory.openSession(); _session.setCacheMode(CacheMode.GET); _session.setDefaultReadOnly(true); _session.setFlushMode(FlushMode.MANUAL); _tx = _session.beginTransaction(); }
From source file:au.com.nicta.ct.db.CtSession.java
License:Open Source License
public static Session Create() { SessionFactory sf = GetSessionFactory(); Session s = sf.openSession(); return s; }
From source file:automata.gui.IngresoAutomata.java
private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed try {/*from www . j a v a 2s . c o m*/ SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); miEstado.setTransicions(transicions); if (rbInicial.isSelected() == true) { jLabel4.setVisible(true); rbInicial.setSelected(false); rbInicial.setEnabled(false); rbNormal.setEnabled(true); rbNormal.setSelected(true); rbFinal.setEnabled(true); miEstado.setInicial(true); } else if (rbNormal.isSelected() == true) { miEstado.setNormal(true); } else { miEstado.setFinal_(true); } session.persist(miEstado); transaction.commit(); transicions.clear(); //Vacial texto de los jtext; txtEstado.setText(null); txtTransicion.setText(null); txtTransicion.setEnabled(false); //Eliminar contenido de la tabla; DefaultTableModel model = (DefaultTableModel) tbTransiciones.getModel(); model.getDataVector().removeAllElements(); model.fireTableDataChanged(); //Desabilitar el boton de guardar btnGuardar.setEnabled(false); if (cbTransiciones.isVisible() == true) { Update_Estado(); } cbTransiciones.setVisible(true); if (rbFinal.isSelected() == true) { BuscaAutomata resolver = new BuscaAutomata(); resolver.getSession(session); resolver.setVisible(true); this.setVisible(false); } Carga_Box(); } catch (HibernateException he) { JOptionPane.showMessageDialog(null, "Hibernate Error: " + he.getMessage()); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error al guardar: " + e.getMessage()); } }
From source file:automatedbillingsoftware_DA.Categories_DA.java
public Categories fetchCategoryByName(String name) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.openSession(); Transaction beginTransaction = session.beginTransaction(); Query query = session.createQuery("from Categories c where c.status=:status AND c.catName LIKE :name"); query.setParameter("status", 1); query.setParameter("name", name); List<Categories> catList = (List<Categories>) query.list(); beginTransaction.commit();/*from www . j a v a 2 s . co m*/ if (catList.size() > 0) return catList.get(0); else return null; }
From source file:automatedbillingsoftware_DA.Categories_DA.java
public Categories fetchCategoryById(int id) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.openSession(); Transaction beginTransaction = session.beginTransaction(); Query query = session.createQuery("from Categories c where c.catid =:catid AND c.status=:status"); query.setParameter("catid", id); query.setParameter("status", 1); List<Categories> catList = (List<Categories>) query.list(); Categories cat = new Categories(); if (catList.size() > 0) { cat = catList.get(0);//from w w w . j av a 2 s . c om } beginTransaction.commit(); return cat; }
From source file:automatedbillingsoftware_DA.ChallanDA.java
public void deleteChallanGen(int id) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.openSession(); ChallanGenerated cg = fetchChallanGenById(id); System.out.println("id=>" + id + "cg=>" + cg); if (cg != null) { Transaction beginTransaction = session.beginTransaction(); cg.setStatus(0);/*from ww w . j ava 2s . c o m*/ session.merge(cg); session.flush(); System.out.println("cg=>" + cg.getStatus()); // challan.setStatus(1); // session.persist(challan); beginTransaction.commit(); } // return challan; }
From source file:automatedbillingsoftware_DA.ChallanDA.java
public Challan fetchChallanByDocNo(String docNo) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.openSession(); Transaction beginTransaction = session.beginTransaction(); Query query = session.createQuery("from Challan where docNo =:docNo"); query.setParameter("docNo", docNo); Challan challan = (Challan) query.list().get(0); beginTransaction.commit();//from ww w . j a va 2 s . c o m return challan; }