Example usage for org.hibernate Session save

List of usage examples for org.hibernate Session save

Introduction

In this page you can find the example usage for org.hibernate Session save.

Prototype

Serializable save(Object object);

Source Link

Document

Persist the given transient instance, first assigning a generated identifier.

Usage

From source file:ar.edu.unju.fi.apu.dao.impl.ProductoDAOImpl.java

@Override
public void altaProducto(Producto producto) {
    producto.setEstado(true);/*from www .j  av  a  2  s. c o  m*/
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();
    session.save(producto);
    session.getTransaction().commit();
    session.close();
}

From source file:ar.edu.unju.fi.apu.dao.impl.TipoProductoDAOImpl.java

@Override
public void altaTipoProducto(TipoProducto tipoProducto) {
    tipoProducto.setEstado(true);//from  w  w w .ja v a  2s .  co  m
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();
    session.save(tipoProducto);
    session.getTransaction().commit();
    session.close();
}

From source file:ar.edu.unju.fi.apu.dao.impl.UsuarioDAOImpl.java

@Override
public void agregarUsuario(Usuario unUsuario) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();// w  ww .  j  av a  2 s .  com
    session.save(unUsuario);
    session.getTransaction().commit();
    session.close();
}

From source file:aseguradora.HospitalVentana.java

private void insertarHospital() {
    try {//from   w w w .  java2s .c o m

        Session session = sesion.openSession();
        Transaction tx = session.beginTransaction();
        Hospital hospital = new Hospital();
        hospital.setCodH(Short.parseShort(etCodHospital.getText().toString()));
        hospital.setNH(etNomHospital.getText().toString());
        hospital.setNumC(Short.parseShort(etNumC.getText()));
        session.save(hospital);
        tx.commit();
        session.close();
        cargarHospital();
    } catch (HibernateException e) {
        e.printStackTrace();
        if (e.getMessage().contains("" + CLAVE_PRIMARIA_DUPLICADA)) {
            JOptionPane.showMessageDialog(rootPane, "Existe un hospital con ese identificador (ID)");
        }
        if (e.getMessage().contains("" + VALOR_DEMASIADO_LARGO)) {
            JOptionPane.showMessageDialog(rootPane, "Has introducido un valor demasiado largo");
        }
    }
}

From source file:aseguradora.MedicoVentana.java

private void insertarMedico() {
    try {// w w  w  . ja  v a2s.  c om

        Session session = sesion.openSession();
        Transaction tx = session.beginTransaction();
        Medico medico = new Medico();
        Hospital hospital = new Hospital(Short.parseShort(etCodHospital.getText().toString()));
        medico.setCodM(Short.parseShort(etCodMedico.getText().toString()));
        medico.setNM(etNomMedico.getText().toString());
        medico.setHospital(hospital);
        session.save(medico);
        tx.commit();
        session.close();

        cargarMedico();
    } catch (JDBCException e) {
        e.printStackTrace();
        if (e.getErrorCode() == CLAVE_PRIMARIA_DUPLICADA) {
            JOptionPane.showMessageDialog(rootPane, "Existe un mdico con ese identificador (ID)");
        }
        if (e.getErrorCode() == CLAVE_AJENA_NO_ENCONTRADA) {
            JOptionPane.showMessageDialog(rootPane, "No existe un hospital con ese identificador (ID)");
        }
        if (e.getErrorCode() == VALOR_DEMASIADO_LARGO) {
            JOptionPane.showMessageDialog(rootPane, "Has introducido un valor demasiado largo");
        }
    }
}

From source file:aseguradora.VistaVentana.java

private void insertarAsegurado() {
    try {/*  www  . jav  a2s  . c  o  m*/
        Date fechaAsegurado = (Date) jsFechaAsegurado.getValue();
        Session session = sesion.openSession();
        Transaction tx = session.beginTransaction();
        PolizasAsegurados pa = new PolizasAsegurados(
                new PolizasAseguradosId(Integer.parseInt(etCodPoliza.getText()), etDatosPoliza.getText(),
                        Integer.parseInt(etNumAsegurado.getText())));
        System.out.println("CODPOLIZA: " + Integer.parseInt(etCodPoliza.getText()));
        pa.getId().setCodP(Integer.parseInt(etCodPoliza.getText()));
        pa.getId().setDatosP(etDatosPoliza.getText());
        pa.getId().setNum(Integer.parseInt(etNumAsegurado.getText()));
        pa.getId().setNa(etNomAsegurado.getText());
        pa.getId().setFn(fechaAsegurado);
        session.save(pa);
        tx.commit();
        session.close();

        cargarVista();
    } catch (JDBCException e) {
        e.printStackTrace();
        if (e.getErrorCode() == CLAVE_PRIMARIA_DUPLICADA) {
            JOptionPane.showMessageDialog(rootPane, "Existe un asegurado con ese identificador (ID)");
        }
        if (e.getErrorCode() == CLAVE_AJENA_NO_ENCONTRADA) {
            JOptionPane.showMessageDialog(rootPane, "No existe una pliza con ese identificador (ID)");
        }
        if (e.getErrorCode() == VALOR_DEMASIADO_LARGO) {
            JOptionPane.showMessageDialog(rootPane, "Has introducido un valor demasiado largo");
        }
    }
}

From source file:ash.resourcemanager.hibernate.GenericDAO.java

public Integer create(T o) {
    Session session = getSession();
    Transaction transaction = session.beginTransaction();
    Integer result = (Integer) session.save(o);
    transaction.commit();//from  w  w  w .  ja va 2 s . co m
    return result;
}

From source file:at.ac.tuwien.infosys.jcloudscale.datastore.hibernate.work.AddWork.java

License:Apache License

private void save(Session session, List<DatastoreModel> datastoreModels) {
    for (DatastoreModel datastoreModel : datastoreModels) {
        session.save(datastoreModel);
    }/*from w w w .  j  ava  2  s  .  c o m*/
}

From source file:at.fhv.lindale.impl.hf.HibernateFacade.java

private void saveContainer(I_Container container) {
    Session session = null;
    Transaction tx = null;/* ww w .  j  a  v  a2s. co  m*/
    try {
        session = sessionFactory.openSession();
        tx = session.beginTransaction();
        session.save(container);
        tx.commit();
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:au.com.nicta.ct.db.CtKeyValueProperties.java

License:Open Source License

public static void persist(CtPropertiesTypes pt, String key, String value) {

    CtProperties p = new CtProperties();

    p.setCtPropertiesTypes(pt);/*  ww w.  j  a  va 2  s  .  co  m*/
    p.setName(key);
    p.setValue(value);

    Session s = CtSession.Create();

    try {
        s.beginTransaction();
        s.save(p);
        s.getTransaction().commit();
    } catch (Exception e) {
    } finally {
        s.close();
    }

    if (useReadCaching) {
        od.put(key, value);
    }
    //s.beginTransaction();
    //s.merge( p );
    //        return p;
}