public void save(Reserva reserva) throws ServiceException { if (reserva.getCampo() == null) { throw new ServiceException("Informe o campo"); } if (reserva.getDataReserva() == null) { throw new ServiceException("Informe a dia da reserva"); } if (reserva.getHoraReserva() == null) { throw new ServiceException("Informe a hora da reserva"); } if (reserva.getUsuario() == null) { throw new ServiceException("Ocorreu um erro ao cadastrar, usuario nulo"); } Reserva _reserva = (Reserva) oneByQuery( "SELECT r FROM Reserva r WHERE r.campo.id = ? AND r.dataReserva = ? AND r.horaReserva = ?", reserva.getCampo().getId(), reserva.getDataReserva(), reserva.getHoraReserva()); if (_reserva != null) { throw new ServiceException("Este campo já esta reservado nesta hora"); } reserva.setDataCadastro(Calendar.getInstance()); reserva.setCampo(getEntityManager().find(Campo.class, reserva.getCampo().getId())); reserva.setUsuario(getEntityManager().find(Usuario.class, reserva.getUsuario().getId())); super.save(reserva); }