public static void removeSpec() { String id = params.get("id"); Specification spec = Specification.findById(Long.valueOf(id)); List<Request> requests = Request.em() .createQuery( "select r from Request r join fetch r.specifications s where s.id=" + Long.valueOf(id), Request.class) .getResultList(); for (Request req : requests) { req.specifications.remove(spec); req.save(); } if (spec != null) spec.delete(); renderText(id); }