HHH-7861 EntityManager.find() should return null instead of EntityNotFoundException
This commit is contained in:
parent
d339e94491
commit
2f0bd59431
|
@ -807,6 +807,14 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
|
||||||
return ( A ) getSession().get( entityClass, ( Serializable ) primaryKey );
|
return ( A ) getSession().get( entityClass, ( Serializable ) primaryKey );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
catch ( ObjectDeletedException e ) {
|
catch ( ObjectDeletedException e ) {
|
||||||
//the spec is silent about people doing remove() find() on the same PC
|
//the spec is silent about people doing remove() find() on the same PC
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -33,10 +33,13 @@ import org.jboss.logging.MessageLogger;
|
||||||
|
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
|
||||||
|
import static org.jboss.logging.Logger.Level.DEBUG;
|
||||||
import static org.jboss.logging.Logger.Level.ERROR;
|
import static org.jboss.logging.Logger.Level.ERROR;
|
||||||
import static org.jboss.logging.Logger.Level.INFO;
|
import static org.jboss.logging.Logger.Level.INFO;
|
||||||
import static org.jboss.logging.Logger.Level.WARN;
|
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
|
* The jboss-logging {@link MessageLogger} for the hibernate-entitymanager module. It reserves message ids ranging from
|
||||||
* 15001 to 20000 inclusively.
|
* 15001 to 20000 inclusively.
|
||||||
|
@ -100,4 +103,11 @@ public interface EntityManagerMessageLogger extends CoreMessageLogger {
|
||||||
@LogMessage( level = INFO )
|
@LogMessage( level = INFO )
|
||||||
@Message( value = "Using provided datasource", id = 15012 )
|
@Message( value = "Using provided datasource", id = 15012 )
|
||||||
void usingProvidedDataSource();
|
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 );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue