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?

skuntsel
  • 11,624
  • 11
  • 44
  • 67
Jonatas Grosman
  • 312
  • 2
  • 3
  • 8

1 Answers1

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.

Community
  • 1
  • 1
Rob
  • 6,247
  • 2
  • 25
  • 33