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:be.facet.it.dojo.customershibernate.repository.PurchaseRepository.java

@Override
public void save(Purchase entity) {
    Session session = this.startTransaction();
    session.save(entity);
    this.stopTransaction(session);
}

From source file:be.shad.tsqb.test.ExamplesTest.java

License:Apache License

@Test
public void testSelectMaxAge() {
    Session session = getSessionFactory().getCurrentSession();
    Town town = new Town();
    town.setId(1L);/*from  w  w w. j  a  va2s.  c om*/
    town.setGeographicCoordinate(new GeographicCoordinate());
    town.getGeographicCoordinate().setLattitude(1d);
    town.getGeographicCoordinate().setLongitude(1d);
    session.save(town);

    Person person = new Person();
    person.setId(1L);
    person.setAge(50);
    person.setTown(town);
    session.save(person);

    Person personProxy = query.from(Person.class);

    PersonDto dto = query.select(PersonDto.class);
    dto.setPersonAge(query.hqlFunction().max(personProxy.getAge()).select());

    validate("select max(hobj1.age) as personAge from Person hobj1");
}

From source file:Beans.ajusteProfesorInfo.java

public boolean Insert_Dispo(Disponibilidad dis) {
    System.out.println("entro al insert dispo " + dis.getCodDis());
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction t = session.beginTransaction();
    boolean r = false;
    System.out.println("codigooooo disssssssssssssssssssssss : " + dis.getCodDis());

    try {/*w  ww  .  j a v a  2s .  c o m*/
        session.save(dis);
        t.commit();
        r = true;
    } catch (Exception ex) {
        System.out.println("Error Insert Dispo " + ex.toString());
        r = false;
    }
    return r;
}

From source file:Beans.ajusteProfesorInfo.java

public boolean InsertDispo_Usu(DispoUsuario dis_usu) {
    System.out.println("----- entro ");
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction t = session.beginTransaction();
    boolean r = false;
    try {//  ww w .  j a va  2s.c  o  m
        session.save(dis_usu);
        t.commit();
        r = true;
    } catch (Exception ex) {
        System.out.println("Error Insert Dispo_Usu" + ex.toString());
        r = false;
    }
    return r;
}

From source file:Beans.ajusteProfesorInfo.java

public boolean Insert_Dias(Disponibilidad dis, ArrayList dias) {
    boolean r = false;
    MDias temp = null;//  www. j ava  2 s .  c  om
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction t = session.beginTransaction();
    int cod_dia = 0;
    System.out.println("codigo de dispo " + dis.getCodDis());
    try {
        cod_dia = Secuencia.seque("select max(codigo_dia) from dia");
        for (int i = 0; i < dias.size(); i++) {
            temp = (MDias) dias.get(i);
            Dia d = new Dia();
            d.setCodigoDia(new BigDecimal(cod_dia));
            d.setDia(temp.getDia());
            d.setHoraInicial(temp.getHora_inicio());
            d.setHoraFinal(temp.getHora_final());
            d.setDisponibilidad(dis);
            session.save(d);
            cod_dia++;
            r = true;
        }
        t.commit();
    } catch (Exception ex) {
        System.out.println("Error Dias " + ex.toString());
        r = false;
    }
    return r;
}

From source file:Beans.ajusteProfesorInfo.java

public void crearUsuRol(Usuario u) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    Transaction t = session.beginTransaction();
    try {//from  w ww . j  a v  a 2  s.  c om
        System.out.println("entro");
        Rol r = new Rol();
        r.setCodRol(new BigDecimal(4));
        r.setEstado("esta");
        r.setNombre("nombre");
        UsuRol usuR = new UsuRol();
        int cod_U = Secuencia.seque("select max(cod_usurol) from usu_rol");
        usuR.setCodUsurol(new BigDecimal(cod_U));
        usuR.setUsuario(u);
        usuR.setRol(r);
        session.save(usuR);
        t.commit();
    } catch (Exception ex) {
        System.out.println("Error al crear usu_rol");
        System.out.println("-- " + ex.toString());
    }

}

From source file:beans.Cart.java

/**
 * Register a new user according to the given data and navigate to the index
 * page if it is successful./*ww  w . j  a  v  a2  s .  c  om*/
 */
public String register() {
    if (loginData.getNev() != null && loginData.getEmail() != null && loginData.getUsername() != null
            && loginData.getPassword() != null) {
        Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.save(loginData);
        session.getTransaction().commit();
        session.close();
        return logInOut(constants.getRegister(), constants.getIndex());
    }
    return "";
}

From source file:beans.Cart.java

/**
 * Store the order and order items into the database.
 *
 * @return the navigation text//from   ww w . ja  va  2  s.c  o m
 */
public String purchase() {
    if (client == null) {
        return constants.getCart() + "2" + constants.getLogin();
    } else {
        //            Set<Orderitem> orderSet = new HashSet<Orderitem>();
        //            for (Orderitem oi : orderList) {
        //                orderSet.add(oi);
        //            }

        Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        session.save(order);
        for (Orderitem oi : orderList) {
            oi.setOrder(order);
            order.getOrderitems().add(oi);
            session.save(oi);
        }
        session.getTransaction().commit();
        session.close();
        return "";
    }
}

From source file:beans.Catalog.java

public String newFilm() {
    for (Datastore ds : datastoreList) {
        if (ds.toString().equals(actDatastore)) {
            newFilmIns.setDatastore(ds);
        }/*ww  w .  j  av a 2  s  . c o  m*/
    }
    Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();
    session.save(newFilmIns);
    session.getTransaction().commit();
    session.close();
    newFilmIns = new Film();
    changeStatusMessage("Addition of the new film was successful.");
    queryFilmsFromDB();
    return "newfilm2index";
}

From source file:beans.Catalog.java

public String newDatastore() {
    Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();//from   w  w  w. j a  v  a  2  s. c o m
    session.save(newDatastoreIns);
    session.getTransaction().commit();
    session.close();
    newDatastoreIns = new Datastore();
    changeStatusMessage("Addition of new datastore was successful.");
    queryDatastoreFromDB();
    return "newdatastore2datastores";
}