Throw UnknownSqlResultSetMappingException for non existing StoreProcedure result mapping

This commit is contained in:
Andrea Boriero 2022-01-31 11:26:12 +01:00 committed by Andrea Boriero
parent b139967be1
commit 5446291171
2 changed files with 40 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import java.util.function.Consumer;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.UnknownSqlResultSetMappingException;
import org.hibernate.query.internal.ResultSetMappingResolutionContext;
import org.hibernate.query.named.NamedObjectRepository;
import org.hibernate.query.named.NamedResultSetMappingMemento;
@ -57,6 +58,9 @@ public class Util {
for ( String resultSetMappingName : resultSetMappingNames ) {
final NamedResultSetMappingMemento memento = namedObjectRepository.getResultSetMappingMemento( resultSetMappingName );
if ( memento == null ) {
throw new UnknownSqlResultSetMappingException( "Unknown SqlResultSetMapping [" + resultSetMappingName + "]" );
}
memento.resolve(
resultSetMapping,
querySpaceConsumer,

View File

@ -0,0 +1,36 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.jpa.compliance;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@Jpa
public class StoreProcedureTest {
@Test
public void createNotExistingStoredProcedureQuery(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {
Assertions.assertThrows(
IllegalArgumentException.class,
() -> {
entityManager.createStoredProcedureQuery(
"NOT_EXISTING_NAME",
"NOT_EXISTING_RESULT_MAPPING"
)
.execute();
}
);
} );
}
}