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

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

From source file:cimitero.rest.ReminderRESTService.java

@POST
public ResponseDto updateReminder(ReminderDto reminderDto) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*  w w 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.ReminderRESTService.java

@DELETE
@Path("{id}")
public ResponseDto removeReminder(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from ww w  . ja  va 2 s .co  m*/
    TReminder result = (TReminder) session.get(TReminder.class, id);
    session.delete(result);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.SessionRESTService.java

@GET
@Path("/user")
public ResponseDto getCurrentUser() {
    ResponseDto response = new ResponseDto(true);
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from ww w .j ava  2 s.co m
    TUser user = (TUser) session.get(TUser.class,
            Integer.parseInt(req.getSession().getAttribute("userId").toString()));
    if (user != null) {
        UserDto userDto = new UserDto(user.getId(), user.getUsername(), user.isIsAdmin(),
                user.getCustomer().getPersonId());
        List<UserDto> results = new ArrayList<UserDto>();
        results.add(userDto);
        response.setItems(new ItemWrapper(results));
    } else {
        response.setOk(false);
        response.addError(1, "current user not found");
    }
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.TombRequestRESTService.java

@GET
@Path("{id}")
public ResponseDto getTombRequestById(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w  w  w .ja  v  a 2  s . c  o  m
    TTombRequest result = (TTombRequest) session.get(TTombRequest.class, id);
    ResponseDto response = new ResponseDto(true);
    if (result == null) {
        response.setOk(false);
        response.addError(1, "reminder with id " + id + " not found");
    } else {
        List<TTombRequest> results = new ArrayList<TTombRequest>();
        results.add(result);
        response.setItems(new ItemWrapper(results));
    }
    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();/*  w w  w  . j a v  a2  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.TombRequestRESTService.java

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

From source file:cimitero.rest.TombRESTService.java

@GET
@Path("{id}")
public ResponseDto getTombById(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*w ww  . j ava  2  s  . co m*/
    TTomb result = (TTomb) session.get(TTomb.class, id);
    ResponseDto response = new ResponseDto(true);
    if (result == null) {
        response.setOk(false);
        response.addError(1, "tomb with id " + id + " not found");
    } else {
        List<TTomb> results = new ArrayList<TTomb>();
        results.add(result);
        response.setItems(new ItemWrapper(results));
    }
    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  .  j  a v a 2s . 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:cimitero.rest.TombRESTService.java

@DELETE
@Path("{id}")
public ResponseDto removeTomb(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();// ww  w. ja v a  2s  .  co  m
    TTomb result = (TTomb) session.get(TTomb.class, id);
    session.delete(result);
    ResponseDto response = new ResponseDto(true);
    session.getTransaction().commit();
    return response;
}