Skip to content

Commit

Permalink
HHH-7861 EntityManager.find() should return null instead of EntityNot…
Browse files Browse the repository at this point in the history
…FoundException (message improvement)
  • Loading branch information
scottmarlow committed Jan 24, 2013
1 parent a0389ff commit 7833527
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Expand Up @@ -810,9 +810,11 @@ public <A> A find(Class<A> entityClass, Object primaryKey, LockModeType lockMode
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 ) {
Expand Down
Expand Up @@ -38,8 +38,6 @@
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.
Expand Down Expand Up @@ -105,9 +103,9 @@ void unableToLocateStaticMetamodelField( String name,
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);

}

0 comments on commit 7833527

Please sign in to comment.