Example usage for org.hibernate Session delete

List of usage examples for org.hibernate Session delete

Introduction

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

Prototype

void delete(Object object);

Source Link

Document

Remove a persistent instance from the datastore.

Usage

From source file:Ciclo.editaCiclo.java

private boolean eliminar(String idCiclo) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//  www  . java2s.c o m
        session.beginTransaction();
        actor = (Ciclo) session.get(Ciclo.class, Integer.parseInt(idCiclo));

        if (actor.getOrdens().isEmpty() == false) {
            session.getTransaction().rollback();
            JOptionPane.showMessageDialog(null, "El ciclo esta en uso en una orden no se puede eliminar!");
            return false;
        } else {
            session.delete(actor);
            session.getTransaction().commit();
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
        session.getTransaction().rollback();
        return false;
    } finally {
        if (session.isOpen())
            session.close();
    }
}

From source file:cimitero.rest.BodyRESTService.java

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

From source file:cimitero.rest.CemetryGroundRESTService.java

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

From source file:cimitero.rest.CemetryGroundRESTService.java

@POST
@Path("/{cemetryGroundId}/borders")
public ResponseDto setCemetryGroundBorders(@PathParam("cemetryGroundId") Integer cemetryGroundId,
        List<CoordinateDto> coordinates) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//  w  w w .  ja v  a2 s  .c om
    TCemetryGround tmpCemetryGround = (TCemetryGround) session.get(TCemetryGround.class, cemetryGroundId);
    ResponseDto response = new ResponseDto(true);
    if (tmpCemetryGround == null) {
        response.setOk(false);
        response.addError(1, "there is no cemetry ground with id " + cemetryGroundId);
    } else {
        for (TCoordinate coordToDelete : tmpCemetryGround.getBoundaryCoordinates()) {
            session.delete(coordToDelete);
        }
        List<TCoordinate> coordinatesList = new ArrayList<TCoordinate>();
        for (CoordinateDto coordinate : coordinates) {
            TCoordinate coord = new TCoordinate(coordinate.getX(), coordinate.getY());
            coord.setCemetryGroundBoundary(tmpCemetryGround);
            session.save(coord);
            coordinatesList.add(coord);
        }
        tmpCemetryGround.setBoundaryCoordinates(coordinatesList);
    }
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.CemetryGroundRESTService.java

@POST
@Path("/{cemetryGroundId}/track")
public ResponseDto setCemetryGroundTrack(@PathParam("cemetryGroundId") Integer cemetryGroundId,
        List<CoordinateDto> coordinates) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from   w w  w . j a  v a 2 s.c  o  m
    TCemetryGround tmpCemetryGround = (TCemetryGround) session.get(TCemetryGround.class, cemetryGroundId);
    ResponseDto response = new ResponseDto(true);
    if (tmpCemetryGround == null) {
        response.setOk(false);
        response.addError(1, "there is no cemetry ground with id " + cemetryGroundId);
    } else {
        for (TCoordinate coordToDelete : tmpCemetryGround.getTrackCoordinates()) {
            session.delete(coordToDelete);
        }
        List<TCoordinate> coordinatesList = new ArrayList<TCoordinate>();
        for (CoordinateDto coordinate : coordinates) {
            TCoordinate coord = new TCoordinate(coordinate.getX(), coordinate.getY());
            coord.setCemetryGroundTrack(tmpCemetryGround);
            session.save(coord);
            coordinatesList.add(coord);
        }
        tmpCemetryGround.setTrackCoordinates(coordinatesList);
    }
    session.getTransaction().commit();
    return response;
}

From source file:cimitero.rest.CemetryRESTService.java

@DELETE
@Path("{id}")
public ResponseDto removeCemetry(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w ww . j  a  v  a 2s.c o  m
    TCemetry result = (TCemetry) session.get(TCemetry.class, id);
    session.delete(result);
    ResponseDto response = new ResponseDto(true);
    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();// w  ww  .j a va2  s . c  o  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

@DELETE
@Path("{id}")
public ResponseDto removeCoordinate(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();//from w  w  w  .  j  a va 2 s  . c  om
    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

@DELETE
@Path("{id}")
public ResponseDto removeInvoice(@PathParam("id") Integer id) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();/*from  w w w . j a  va2  s  . c  o m*/
    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

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