@Override public void delete(Flight entity) { try { Util.validateFlight(entity); if (entity.getId() == null) { throw new IllegalArgumentException("This flight entity cannot have null id."); } if (em.find(Flight.class, entity.getId()) == null) { throw new IllegalArgumentException("This flight entity does not exist in database."); } Flight objectTemp = em.merge(entity); em.remove(objectTemp); } catch (PersistenceException | IllegalArgumentException ex) { throw new DataAccessException(ex.getMessage(), ex) {}; } }
@Override public void create(Flight entity) { try { Util.validateFlight(entity); if (entity.getId() != null) { throw new IllegalArgumentException("This flight entity is already in database."); } em.persist(entity); em.flush(); em.detach(entity); } catch (PersistenceException | IllegalArgumentException ex) { throw new DataAccessException(ex.getMessage(), ex) {}; } }