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.ReminderRESTService.java

@POST
public ResponseDto updateReminder(ReminderDto reminderDto) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*  ww w  . j  a v a 2s.  c  om*/
    TReminder tmpReminder = new TReminder(reminderDto.getReminderId(), reminderDto.getInvoiceDate(),
            reminderDto.getPaymentDate(), reminderDto.getCharges());
    TInvoice tmpInvoice = (TInvoice) session.get(TInvoice.class, reminderDto.getInvoiceId());
    tmpReminder.setInvoice(tmpInvoice);
    if (reminderDto.getReminderId() == -1)
        tmpReminder.setReminderId(null);
    session.saveOrUpdate(tmpReminder);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.TombRequestRESTService.java

@POST
public ResponseDto updateTombRequest(TombRequestDto tombRequestDto) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   w  ww. ja  va2  s .co m*/
    TTombRequest tmpTombRequest = new TTombRequest(tombRequestDto.getTombRequestId(),
            tombRequestDto.getRequestDate(), tombRequestDto.getRequestText());
    TTomb tmpTomb = (TTomb) session.get(TTomb.class, tombRequestDto.getTombId());
    tmpTombRequest.setTomb(tmpTomb);
    TCustomer tmpCustomer = (TCustomer) session.get(TCustomer.class, tombRequestDto.getPersonId());
    tmpTombRequest.setCustomer(tmpCustomer);
    if (tombRequestDto.getTombRequestId() == -1)
        tmpTombRequest.setTombRequestId(null);
    session.saveOrUpdate(tmpTombRequest);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.TombRESTService.java

@POST
public ResponseDto updateTomb(TombDto tombDto) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from   w w w  .ja v a 2  s. c o m*/
    TTomb tmpTomb = new TTomb(tombDto.getTombId(), tombDto.getTombNo());
    TCemetryGround tmpCemetryGround = (TCemetryGround) session.get(TCemetryGround.class,
            tombDto.getCemetryGroundId());
    tmpTomb.setCemetryGround(tmpCemetryGround);
    TCustomer tmpCustomer = (TCustomer) session.get(TCustomer.class, tombDto.getPersonId());
    tmpTomb.setCustomer(tmpCustomer);
    if (tombDto.getTombId() == -1)
        tmpTomb.setTombId(null);
    session.saveOrUpdate(tmpTomb);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}

From source file:cn.newtouch.model.TeacherTest.java

License:Open Source License

@Test
public void testSaveOrUpdate() {

    Teacher t = new Teacher();
    t.setName("t1");
    t.setTitle("middle");
    t.setBirthDate(new Date());

    Session session = HibernateUtil.getSession();
    session.beginTransaction();//from www. j av  a2 s . c  o  m
    session.saveOrUpdate(t);

    session.getTransaction().commit();

    t.setName("t2");

    Session session2 = HibernateUtil.getSession();
    session2.beginTransaction();
    session2.saveOrUpdate(t);
    session2.getTransaction().commit();

}

From source file:co.utb.softeng.contactsapp.dao.impl.ContactDAOImpl.java

public Contact addCitasToContact(List<Cita> citas, Long contactId) {
    Session session = getSession();
    Contact contact = (Contact) session.get(Contact.class, contactId);

    //Lado dominante es Contact
    contact.getCitas().addAll(citas);/*from w w w  .  j  ava  2s.  c  om*/
    session.saveOrUpdate(contact);

    return contact;
}

From source file:com.abc.salesinventory.service.newpackage.InventoryServiceImpl.java

@Override
public String saveStock(Stock stock) throws HibernateException {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*from www  .  ja v a2  s .c  o  m*/
    session.saveOrUpdate(stock);
    session.getTransaction().commit();
    session.close();
    return stock.getStockId();
}

From source file:com.abc.salesinventory.service.newpackage.InventoryServiceImpl.java

@Override
public String saveTransaction(Transaction transaction) throws HibernateException {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();//from  w  w w  .j  a  v  a 2s .c om
    session.saveOrUpdate(transaction);
    session.getTransaction().commit();
    session.close();
    return transaction.getTransactionId();
}

From source file:com.abc.salesinventory.service.newpackage.MasterServiceImpl.java

@Override
public String saveOrUpdateCustomer(Customer customer) throws HibernateException {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*  ww w.  j av  a  2  s.  c om*/
    session.saveOrUpdate(customer);
    session.getTransaction().commit();
    session.close();
    return customer.getId();
}

From source file:com.abc.salesinventory.service.newpackage.MasterServiceImpl.java

@Override
public String saveMessage(Message message) throws HibernateException {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*from w ww  .  jav a2s .co  m*/
    session.saveOrUpdate(message);
    session.getTransaction().commit();
    session.close();
    return message.getId();
}

From source file:com.abc.salesinventory.service.newpackage.MasterServiceImpl.java

@Override
public String saveOrUpdateSupplier(Supplier supplier) throws HibernateException {
    Session session = HibernateUtil.getSessionFactory().openSession();
    session.beginTransaction();/*from www.ja v a2s  .c o m*/
    session.saveOrUpdate(supplier);
    session.getTransaction().commit();
    session.close();
    return supplier.getId();
}