Hello,
The EJB spec version 3.0 public draft does not contain detailed information on the different types of exceptions and the exception handling strategies but I noticed the following discrepancy:
Page 38 describes the find operation on the EntityManager interface:
Code:
/**
* Find by primary key.
* @param entityClass
* @param primaryKey
* @return the found entity instance or null
* if the entity does not exist
* @throws IllegalArgumentException if the first argument does
* not denote an entity type or the second
* argument is not a valid type for that
* entity’s primary key
*/
public <T> T find(Class<T> entityClass, Object primaryKey);
Page 50 describes the getSingleResult operation on the Query interface:
Code:
/**
* Execute a SELECT query that returns a single result.
* @return the result
* @throws EntityNotFoundException if there is no result
* @throws NonUniqueResultException if more than one result
* @throws IllegalStateException if called for an EJB QL
* UPDATE or DELETE statement
*/
public Object getSingleResult();
Why does the find method return null if the entity does not exist, whereas the getSingleResult operation throws an EntityNotFoundException if there is no result?
Kind regards,
Stijn Janssens