0

I'm using Netbeans IDE and EclipseLink JPA implementation.

According to Netbeans, this code is valid:

public void save(T entity) {        
    EntityManager entityManager = JPAUtil.getEntityManager();
    entityManager.getTransaction().begin();
    entityManager.persist(entity);
    entityManager.getTransaction().commit();
}

But I think, that really valid code is:

public void save(T entity) throws PersistenceException {        
    EntityManager entityManager = JPAUtil.getEntityManager();
    entityManager.getTransaction().begin();
    entityManager.persist(entity);
    entityManager.getTransaction().commit();
}

Why this is happening?

1 Answer 1

1

PersistenceException extends RuntimeException. This means that is an "unchecked" exception so it does not have to be explicitly declared or handled.

See this question for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.