Example usage for org.hibernate Session get

List of usage examples for org.hibernate Session get

Introduction

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

Prototype

Object get(String entityName, Serializable id);

Source Link

Document

Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.

Usage

From source file:cimitero.rest.CoordinateRESTService.java

@GET
@Path("{id}")
public ResponseDto getCoordinateById(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w ww.java 2 s.c  om
    TCoordinate result = (TCoordinate) session.get(TCoordinate.class, id);
    ResponseDto response = new ResponseDto(true);
    if (result == null) {
        response.setOk(false);
        response.addError(1, "coordinate with id " + id + " not found");
    } else {
        List<TCoordinate> results = new ArrayList<TCoordinate>();
        results.add(result);
        response.setItems(new ItemWrapper(results));
    }
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.CoordinateRESTService.java

@DELETE
@Path("{id}")
public ResponseDto removeCoordinate(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  www  .  j  a v a  2s. co  m*/
    TCoordinate result = (TCoordinate) session.get(TCoordinate.class, id);
    session.delete(result);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.CustomerRESTService.java

@GET
@Path("{id}")
public ResponseDto getCustomerById(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from  ww  w .java 2 s  .  c o  m
    TCustomer result = (TCustomer) session.get(TCustomer.class, id);
    ResponseDto response = new ResponseDto(true);
    if (result == null) {
        response.setOk(false);
        response.addError(1, "customer with id " + id + " not found");
    } else {
        List<TCustomer> results = new ArrayList<TCustomer>();
        results.add(result);
        response.setItems(new ItemWrapper(results));
    }
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.CustomerRESTService.java

@POST
public ResponseDto updateCustomer(CustomerDto customerDto) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w  w w . java  2s .  co m
    if (customerDto.getGebDatum() != null) {
        customerDto.setGebDatum(new Date(customerDto.getGebDatum().getTime()));
    }
    TCustomer tmpCustomer = new TCustomer(customerDto.getPersonId(), customerDto.getTitle(),
            customerDto.getFirstName(), customerDto.getLastName(), customerDto.getOtherFirstNames(),
            customerDto.getGebDatum(), customerDto.getAddress(), customerDto.getTelephoneNumber());
    List<TTomb> tmpTombs = new ArrayList<TTomb>();
    if (customerDto.getTombIds() != null) {
        for (Integer tombId : customerDto.getTombIds()) {
            TTomb tmpTomb = (TTomb) session.get(TTomb.class, tombId);
            if (tmpTomb != null)
                tmpTombs.add(tmpTomb);
        }
    }
    //if(tmpTombs.size() > 0 && customerDto.getTombIds() != null) tmpCustomer.setTombs(tmpTombs);
    if (customerDto.getPersonId() == -1)
        tmpCustomer.setPersonId(null);
    session.saveOrUpdate(tmpCustomer);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.CustomerRESTService.java

@DELETE
@Path("{id}")
public ResponseDto removeCoordinate(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   www. j  av  a  2 s  .c  o m
    TCustomer result = (TCustomer) session.get(TCustomer.class, id);
    session.delete(result);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.InvoiceRESTService.java

@GET
@Path("{id}")
public ResponseDto getInvoiceById(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  w ww .jav  a  2s.  c o  m*/
    TInvoice result = (TInvoice) session.get(TInvoice.class, id);
    ResponseDto response = new ResponseDto(true);
    if (result == null) {
        response.setOk(false);
        response.addError(1, "customer with id " + id + " not found");
    } else {
        List<TInvoice> results = new ArrayList<TInvoice>();
        results.add(result);
        response.setItems(new ItemWrapper(results));
    }
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.InvoiceRESTService.java

@POST
public ResponseDto updateInvoice(InvoiceDto invoiceDto) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//w ww  .j  av  a  2  s. co  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.InvoiceRESTService.java

@DELETE
@Path("{id}")
public ResponseDto removeInvoice(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/* w ww  .  j  av a 2  s .c om*/
    TInvoice result = (TInvoice) session.get(TInvoice.class, id);
    session.delete(result);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.PersonRESTService.java

@GET
@Path("{id}")
public ResponseDto getPersonById(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  w w w. ja v a  2  s  .  co m*/
    TPerson result = (TPerson) session.get(TPerson.class, id);
    ResponseDto response = new ResponseDto(true);
    if (result == null) {
        response.setOk(false);
        response.addError(1, "person with id " + id + " not found");
    } else {
        List<TPerson> results = new ArrayList<TPerson>();
        results.add(result);
        response.setItems(new ItemWrapper(results));
    }
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.PersonRESTService.java

@DELETE
@Path("{id}")
public ResponseDto removePerson(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from w  w w . ja  v a2s .c o  m*/
    TPerson result = (TPerson) session.get(TPerson.class, id);
    session.delete(result);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}