more consistent error message between JPA and plain Hibernate
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
d7aa5f7a78
commit
f95182e736
|
@ -48,7 +48,6 @@ import org.hibernate.proxy.HibernateProxy;
|
|||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.type.CollectionType;
|
||||
import org.hibernate.type.ComponentType;
|
||||
import org.hibernate.type.CompositeType;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.TypeHelper;
|
||||
|
||||
|
@ -315,7 +314,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
|
|||
EntityPersister persister = source.getEntityPersister( entityName, event.getObject() );
|
||||
Object id = persister.getIdentifier( event.getObject(), source );
|
||||
entityName = entityName == null ? source.guessEntityName( event.getObject() ) : entityName;
|
||||
throw new IllegalArgumentException( "Removing a detached instance " + entityName + "#" + id );
|
||||
throw new IllegalArgumentException( "Given entity is not associated with the persistence context [" + entityName + "#" + id + "]" );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.function.Consumer;
|
|||
import javax.sql.DataSource;
|
||||
|
||||
import org.hibernate.Internal;
|
||||
import org.hibernate.ObjectNotFoundException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.SessionFactoryObserver;
|
||||
import org.hibernate.boot.CacheRegionDefinition;
|
||||
|
@ -185,8 +186,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
|
|||
*/
|
||||
public static final JpaEntityNotFoundDelegate INSTANCE = new JpaEntityNotFoundDelegate();
|
||||
|
||||
public void handleEntityNotFound(String entityName, Object id) {
|
||||
throw new EntityNotFoundException( "Unable to find " + entityName + " with id " + id );
|
||||
public void handleEntityNotFound(String entityName, Object identifier) {
|
||||
final ObjectNotFoundException exception = new ObjectNotFoundException( entityName, identifier );
|
||||
throw new EntityNotFoundException( exception.getMessage(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ public class FilterTest extends BaseEntityManagerFunctionalTestCase {
|
|||
() -> Hibernate.initialize( account.getParentAccount() )
|
||||
);
|
||||
// Account with id 1 does not exist
|
||||
assertTrue( exception.getMessage().endsWith( " 1" ) );
|
||||
assertTrue( exception.getMessage().endsWith( "#1]" ) );
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue