Example usage for org.hibernate Session saveOrUpdate

List of usage examples for org.hibernate Session saveOrUpdate

Introduction

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

Prototype

void saveOrUpdate(Object object);

Source Link

Document

Either #save(Object) or #update(Object) the given instance, depending upon resolution of the unsaved-value checks (see the manual for discussion of unsaved-value checking).

Usage

From source file:cimitero.rest.InitRESTService.java

private void fillCemetries() {
    log.info("generating 100 cemetries");
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();// w  ww .j a va 2  s  .  c o  m
    for (int i = 1; i <= 100; i++) {
        TCemetry tmpCemetry = new TCemetry();
        tmpCemetry.setName("Cemetry " + i);
        tmpCemetry.setAddress("Cemetry Street " + i);
        tmpCemetry.setLatitute(1.0);
        tmpCemetry.setLongitude(1.0);
        session.saveOrUpdate(tmpCemetry);
    }
    session.getTransaction().commit();
}

From source file:cimitero.rest.InitRESTService.java

private void fillCemetryGrounds() {
    log.info("generating 100 cemetry grounds");
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  ww w  .  ja  v a 2 s .  c  om
    for (int i = 1; i <= 100; i++) {
        TCemetryGround tmpCemetryGround = new TCemetryGround();
        tmpCemetryGround.setName("Cemetry " + i);
        tmpCemetryGround.setAddress("Cemetry Street " + i);
        tmpCemetryGround.setCemetry(null);
        session.saveOrUpdate(tmpCemetryGround);
    }
    session.getTransaction().commit();
}

From source file:cimitero.rest.InitRESTService.java

private void fillTombs() {
    log.info("generating 100 tombs");
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from www .  j  ava 2 s .  com
    for (int i = 1; i <= 100; i++) {
        TTomb tmpTomb = new TTomb();
        tmpTomb.setTombNo(Integer.toString(i));
        tmpTomb.setCemetryGround(null);
        tmpTomb.setCustomer(null);
        session.saveOrUpdate(tmpTomb);
    }
    session.getTransaction().commit();
}

From source file:cimitero.rest.InitRESTService.java

private void fillTombRequest() {
    log.info("generating 100 tomb request");
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   ww w .ja va  2  s  . c  o  m
    for (int i = 1; i <= 100; i++) {
        TTombRequest tmpTombRequest = new TTombRequest();
        tmpTombRequest.setRequestDate(new Date(1448912890));
        tmpTombRequest.setTomb(null);
        tmpTombRequest.setRequestText("Test Text");
        tmpTombRequest.setCustomer(null);
        session.saveOrUpdate(tmpTombRequest);
    }
    session.getTransaction().commit();
}

From source file:cimitero.rest.InitRESTService.java

private void fillInvoices() {
    log.info("generating 100 invoices");
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w w  w  . j  a  v  a2s .c om
    for (int i = 1; i <= 100; i++) {
        TInvoice tmpInvoice = new TInvoice();
        tmpInvoice.setCurrency("EUR");
        tmpInvoice.setTomb(null);
        tmpInvoice.setTotal((double) i * 10);
        tmpInvoice.setInvoiceDate(new Date(1448912890));
        tmpInvoice.setPaymentDate(new Date(1448912890));
        tmpInvoice.setInvoiceNumber("R00" + i);
        session.saveOrUpdate(tmpInvoice);
    }
    session.getTransaction().commit();
}

From source file:cimitero.rest.InitRESTService.java

private void fillReminders() {
    log.info("generating 100 reminders");
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  ww w. j  a  v  a  2s  .  c  o  m*/
    for (int i = 1; i <= 100; i++) {
        TReminder tmpReminder = new TReminder();
        tmpReminder.setCurrency("EUR");
        tmpReminder.setInvoice(null);
        tmpReminder.setCharges((double) i * 10);
        tmpReminder.setInvoiceDate(new Date(1448912890));
        tmpReminder.setPaymentDate(new Date(1448912890));
        session.saveOrUpdate(tmpReminder);
    }
    session.getTransaction().commit();
}

From source file:cimitero.rest.InitRESTService.java

private void fillPersons() {
    log.info("generating 100 persons");
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//  www .j  av  a 2s .c o m
    for (int i = 1; i <= 100; i++) {
        TCustomer tmpPerson = new TCustomer();
        tmpPerson.setFirstName("First Name " + i);
        tmpPerson.setLastName("Last Name " + i);
        tmpPerson.setAddress("My Street " + i);
        tmpPerson.setGebDatum(Date.valueOf("01.01.1992"));
        tmpPerson.setOtherFirstNames("Other First Name");
        tmpPerson.setTelephoneNumber("0123456789");
        tmpPerson.setTitle("Title");
        session.saveOrUpdate(tmpPerson);
    }
    session.getTransaction().commit();
}

From source file:cimitero.rest.InitRESTService.java

private void fillBodies() {
    log.info("generating 100 bodies");
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* www .ja  v  a 2 s  .c om*/
    for (int i = 1; i <= 100; i++) {
        TBody tmpBody = new TBody();
        tmpBody.setFirstName("First Name " + i);
        tmpBody.setLastName("Last Name " + i);
        tmpBody.setAddress("My Street " + i);
        tmpBody.setGebDatum(Date.valueOf("01.01.1992"));
        tmpBody.setOtherFirstNames("Other First Name");
        tmpBody.setTelephoneNumber("0123456789");
        tmpBody.setTitle("Title");
        tmpBody.setTomb(null);
        session.saveOrUpdate(tmpBody);
    }
    session.getTransaction().commit();
}

From source file:cimitero.rest.InvoiceRESTService.java

@POST
public ResponseDto updateInvoice(InvoiceDto invoiceDto) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w  ww.j  ava2  s . c o  m
    TInvoice tmpInvoice = new TInvoice(invoiceDto.getInvoiceId(), invoiceDto.getInvoiceDate(),
            invoiceDto.getPaymentDate(), invoiceDto.getInvoiceNumber(), invoiceDto.getTotal(),
            invoiceDto.getCurrency());
    TTomb tmpTomb = (TTomb) session.get(TTomb.class, invoiceDto.getTombId());
    tmpInvoice.setTomb(tmpTomb);
    if (invoiceDto.getInvoiceId() == -1)
        tmpInvoice.setInvoiceId(null);
    session.saveOrUpdate(tmpInvoice);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.PersonRESTService.java

@POST
public ResponseDto updatePerson(TPerson person) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//w w w.  java 2  s.c o m
    if (person.getPersonId() == -1)
        person.setPersonId(null);
    session.saveOrUpdate(person);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}