Skip to content

Commit 6036829

Browse files
committed
HHH-7861 EntityManager.find() should return null instead of EntityNotFoundException (message improvement)
1 parent 2f0bd59 commit 6036829

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

hibernate-entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,11 @@ public <A> A find(Class<A> entityClass, Object primaryKey, LockModeType lockMode
810810
catch ( EntityNotFoundException ignored ) {
811811
// DefaultLoadEventListener.returnNarrowedProxy may throw ENFE (see HHH-7861 for details),
812812
// which find() should not throw. Find() should return null if the entity was not found.
813-
if ( LOG.isDebugEnabled() ) {
814-
LOG.ignoringEntityNotFound( entityClass != null ? entityClass.getName(): null, ignored );
815-
}
813+
if ( LOG.isDebugEnabled() ) {
814+
String entityName = entityClass != null ? entityClass.getName(): null;
815+
String identifierValue = primaryKey != null ? primaryKey.toString() : null ;
816+
LOG.ignoringEntityNotFound( entityName, identifierValue );
817+
}
816818
return null;
817819
}
818820
catch ( ObjectDeletedException e ) {

hibernate-entitymanager/src/main/java/org/hibernate/ejb/internal/EntityManagerMessageLogger.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
import static org.jboss.logging.Logger.Level.INFO;
3939
import static org.jboss.logging.Logger.Level.WARN;
4040

41-
import javax.persistence.EntityNotFoundException;
42-
4341
/**
4442
* The jboss-logging {@link MessageLogger} for the hibernate-entitymanager module. It reserves message ids ranging from
4543
* 15001 to 20000 inclusively.
@@ -105,9 +103,9 @@ void unableToLocateStaticMetamodelField( String name,
105103
void usingProvidedDataSource();
106104

107105

108-
@LogMessage( level = DEBUG )
109-
@Message( value = "Returning null (as required by JPA spec) rather than throwing EntityNotFoundException, " +
110-
"as the entity (%s) does not exist", id = 15013 )
111-
void ignoringEntityNotFound( String entityName,
112-
@Cause EntityNotFoundException e );
106+
@LogMessage( level = DEBUG )
107+
@Message( value = "Returning null (as required by JPA spec) rather than throwing EntityNotFoundException, " +
108+
"as the entity (type=%s, id=%s) does not exist", id = 15013 )
109+
void ignoringEntityNotFound( String entityName, String identifier);
110+
113111
}

0 commit comments

Comments
 (0)