@Override
    public void update(int id, Letter letter) {
        EntityManager entityManager = factory.createEntityManager();
        EntityTransaction transaction = entityManager.getTransaction();
        transaction.begin();
        Letter new_letter = entityManager.find(Letter.class, id);
        if (letter.getTitle() != null){
            new_letter.setTitle(letter.getTitle());
        }
        if (letter.getBody() != null){
            new_letter.setBody(letter.getBody());
        }
        if (letter.getTo() != null){
            new_letter.setTo(letter.getTo());
        }
        if (letter.getFrom() != null){
            new_letter.setFrom(letter.getFrom());
        }

        entityManager.merge(new_letter);
        transaction.commit();

    }