From 603682937c998dc645bbcab5fe12f1f2cbcc5de8 Mon Sep 17 00:00:00 2001 From: Scott Marlow Date: Thu, 24 Jan 2013 10:28:40 -0500 Subject: [PATCH] HHH-7861 EntityManager.find() should return null instead of EntityNotFoundException (message improvement) --- .../org/hibernate/ejb/AbstractEntityManagerImpl.java | 8 +++++--- .../ejb/internal/EntityManagerMessageLogger.java | 12 +++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java index c83e734119..4be3b203f9 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java @@ -810,9 +810,11 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage catch ( EntityNotFoundException ignored ) { // DefaultLoadEventListener.returnNarrowedProxy may throw ENFE (see HHH-7861 for details), // which find() should not throw. Find() should return null if the entity was not found. - if ( LOG.isDebugEnabled() ) { - LOG.ignoringEntityNotFound( entityClass != null ? entityClass.getName(): null, ignored ); - } + if ( LOG.isDebugEnabled() ) { + String entityName = entityClass != null ? entityClass.getName(): null; + String identifierValue = primaryKey != null ? primaryKey.toString() : null ; + LOG.ignoringEntityNotFound( entityName, identifierValue ); + } return null; } catch ( ObjectDeletedException e ) { diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/internal/EntityManagerMessageLogger.java b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/internal/EntityManagerMessageLogger.java index 58f851dcf7..e857556e76 100644 --- a/hibernate-entitymanager/src/main/java/org/hibernate/ejb/internal/EntityManagerMessageLogger.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/ejb/internal/EntityManagerMessageLogger.java @@ -38,8 +38,6 @@ import static org.jboss.logging.Logger.Level.ERROR; import static org.jboss.logging.Logger.Level.INFO; import static org.jboss.logging.Logger.Level.WARN; -import javax.persistence.EntityNotFoundException; - /** * The jboss-logging {@link MessageLogger} for the hibernate-entitymanager module. It reserves message ids ranging from * 15001 to 20000 inclusively. @@ -105,9 +103,9 @@ public interface EntityManagerMessageLogger extends CoreMessageLogger { void usingProvidedDataSource(); - @LogMessage( level = DEBUG ) - @Message( value = "Returning null (as required by JPA spec) rather than throwing EntityNotFoundException, " + - "as the entity (%s) does not exist", id = 15013 ) - void ignoringEntityNotFound( String entityName, - @Cause EntityNotFoundException e ); + @LogMessage( level = DEBUG ) + @Message( value = "Returning null (as required by JPA spec) rather than throwing EntityNotFoundException, " + + "as the entity (type=%s, id=%s) does not exist", id = 15013 ) + void ignoringEntityNotFound( String entityName, String identifier); + }