List of usage examples for org.hibernate Session save
Serializable save(Object object);
From source file:appcostal.model.DAO.java
public void Insertar(Object obj) { SessionFactory s = HibernateUtil.getSessionFactory(); Session se; se = s.openSession();//w ww .java 2 s . c o m Transaction tx = se.beginTransaction(); try { se.save(obj); } catch (Exception e) { System.out.println("error"); } tx.commit(); se.close(); }
From source file:appHibernateSebastianLeonte.Main.java
public static void insertar() { SessionFactory session = SessionFactoryUtil.getSessionFactory(); Session s = session.openSession(); Transaction transaction = s.beginTransaction(); System.out.println("Insertando"); Vuelos vuelos = new Vuelos(); vuelos.setCodVuelo("AB-BY-4811"); vuelos.setHoraSalida("02/04/99-14:30"); vuelos.setDestino("Paris"); vuelos.setProcedencia("Madrid"); vuelos.setPlazasFumador(100);/* w ww . ja v a 2 s .c o m*/ vuelos.setPlazasNoFumador(100); vuelos.setPlazasPrimera(100); vuelos.setPlazasTurista(100); s.save(vuelos); transaction.commit(); s.close(); session.close(); }
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);// w w w .j av a 2 s. c o m s.save(vuelos); transaction.commit(); s.close(); session.close(); }
From source file:applicationController.Handlers.GetAllChatsHandler.java
@Override public void handleIt(HashMap inMap, JSONOutputStream outToClient) { Session session = HibernateUtilSingleton.getSessionFactory().getCurrentSession(); Transaction transaction = session.beginTransaction(); Query query = session.createQuery("FROM Meeting WHERE meeting_id = :meeting "); query.setParameter("meeting", this.commBean.convertLong(((HashMap) inMap.get("data")).get("meeting"))); Meeting meeting = (Meeting) query.uniqueResult(); String returnMsg = ""; if (meeting != null) { for (Message msg : meeting.getMessages()) { returnMsg += msg.getUsername() + ": " + msg.getMsg() + "\n"; }/* w ww .j ava 2 s . com*/ } else { Meeting newMeeting = new Meeting(); newMeeting.setMeeting_id(this.commBean.convertLong(((HashMap) inMap.get("data")).get("meeting"))); newMeeting.setName("not named yet"); session.save(newMeeting); } session.getTransaction().commit(); this.commBean.setCommand("SENDCHAT"); HashMap data = new HashMap(); data.put("msg", returnMsg); this.commBean.setData(data); try { outToClient.writeObject(this.commBean); } catch (Exception e) { e.printStackTrace(); } }
From source file:applicationController.Handlers.SendChatHandler.java
@Override public void handleIt(HashMap inMap, JSONOutputStream outToClient) { Session session = HibernateUtilSingleton.getSessionFactory().getCurrentSession(); Transaction transaction = session.beginTransaction(); Query query = session.createQuery("FROM Meeting WHERE meeting_id = :meeting "); query.setParameter("meeting", this.commBean.convertLong(((HashMap) inMap.get("data")).get("meeting"))); Meeting meeting = (Meeting) query.uniqueResult(); Message msg = new Message(); msg.setMeeting(meeting);// w w w . j a va2 s.c o m msg.setUsername(((HashMap) inMap.get("data")).get("username").toString()); msg.setMsg(((HashMap) inMap.get("data")).get("msg").toString()); session.save(msg); session.getTransaction().commit(); this.commBean.setCommand("SENDCHAT"); HashMap data = new HashMap(); data.put("msg", ((HashMap) inMap.get("data")).get("msg").toString()); data.put("username", ((HashMap) inMap.get("data")).get("username").toString()); this.commBean.setData(data); try { outToClient.writeObject(this.commBean); } catch (Exception e) { e.printStackTrace(); } }
From source file:appointment.businessobject.ManageCustomer.java
public Long addCustomer(String fname, String lname) { Session session = factory.openSession(); Transaction tx = null;//from w w w .j a v a 2s . com Long customerID = null; try { tx = session.beginTransaction(); Customer customer = new Customer(); customer.setFirstName(fname); customer.setLastName(lname); customerID = (Long) session.save(customer); tx.commit(); } catch (HibernateException e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); } finally { session.close(); } return customerID; }
From source file:ar.edu.unju.fi.apu.dao.imp.mysql.PacienteDAOImp.java
@Override public void crearPaciente(Paciente paciente) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();/*from w ww . ja v a 2 s.c o m*/ session.save(paciente); session.getTransaction().commit(); session.close(); }
From source file:ar.edu.unju.fi.apu.dao.imp.mysql.PropietarioDAOImp.java
@Override public void crearPropietario(Propietario propietario) { propietario.setEstado(true);// ww w . j a v a 2 s. c o m Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); session.save(propietario); session.getTransaction().commit(); session.close(); }
From source file:ar.edu.unju.fi.apu.dao.impl.EncabezadoFacturaDAOImpl.java
@Override public void altaEncabezadoFactura(EncabezadoFactura encabezadoFactura) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();/*from ww w . j av a 2s.c o m*/ session.save(encabezadoFactura); session.getTransaction().commit(); session.close(); }
From source file:ar.edu.unju.fi.apu.dao.impl.FacturaDetalleDAOImpl.java
@Override public void altaFacturaDetalle(FacturaDetalle facturaDetalle) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();//from ww w . jav a2s .co m session.save(facturaDetalle); session.getTransaction().commit(); session.close(); }