HHH-8515 - EntityManager#createStoredProcedureQuery( String, String...) should throw IAE if result set mapping name(s) do not exist

This commit is contained in:
Steve Ebersole 2013-09-18 08:48:51 -05:00
parent 75dc1138de
commit 31f50f3280
3 changed files with 54 additions and 5 deletions

View File

@ -0,0 +1,42 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.procedure;
import org.hibernate.MappingException;
/**
* @author Steve Ebersole
*/
public class UnknownSqlResultSetMappingException extends MappingException {
private final String unknownSqlResultSetMappingName;
public UnknownSqlResultSetMappingException(String unknownSqlResultSetMappingName) {
super( "The given SqlResultSetMapping name [" + unknownSqlResultSetMappingName + "] is unknown" );
this.unknownSqlResultSetMappingName = unknownSqlResultSetMappingName;
}
public String getUnknownSqlResultSetMappingName() {
return unknownSqlResultSetMappingName;
}
}

View File

@ -35,6 +35,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.loader.custom.sql.SQLQueryReturnProcessor; import org.hibernate.loader.custom.sql.SQLQueryReturnProcessor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.procedure.UnknownSqlResultSetMappingException;
/** /**
* Utilities used to implement procedure call support. * Utilities used to implement procedure call support.
@ -129,7 +130,7 @@ public class Util {
for ( String resultSetMappingName : resultSetMappingNames ) { for ( String resultSetMappingName : resultSetMappingNames ) {
final ResultSetMappingDefinition mapping = context.findResultSetMapping( resultSetMappingName ); final ResultSetMappingDefinition mapping = context.findResultSetMapping( resultSetMappingName );
if ( mapping == null ) { if ( mapping == null ) {
throw new MappingException( "Unknown SqlResultSetMapping [" + resultSetMappingName + "]" ); throw new UnknownSqlResultSetMappingException( "Unknown SqlResultSetMapping [" + resultSetMappingName + "]" );
} }
context.addQueryReturns( mapping.getQueryReturns() ); context.addQueryReturns( mapping.getQueryReturns() );

View File

@ -123,6 +123,7 @@ import org.hibernate.jpa.internal.util.CacheModeHelper;
import org.hibernate.jpa.internal.util.ConfigurationHelper; import org.hibernate.jpa.internal.util.ConfigurationHelper;
import org.hibernate.jpa.internal.util.LockModeTypeHelper; import org.hibernate.jpa.internal.util.LockModeTypeHelper;
import org.hibernate.procedure.ProcedureCallMemento; import org.hibernate.procedure.ProcedureCallMemento;
import org.hibernate.procedure.UnknownSqlResultSetMappingException;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.transform.BasicTransformerAdapter; import org.hibernate.transform.BasicTransformerAdapter;
@ -944,10 +945,15 @@ public abstract class AbstractEntityManagerImpl implements HibernateEntityManage
public StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings) { public StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings) {
checkOpen(); checkOpen();
try { try {
return new StoredProcedureQueryImpl( try {
internalGetSession().createStoredProcedureCall( procedureName, resultSetMappings ), return new StoredProcedureQueryImpl(
this internalGetSession().createStoredProcedureCall( procedureName, resultSetMappings ),
); this
);
}
catch (UnknownSqlResultSetMappingException unknownResultSetMapping) {
throw new IllegalArgumentException( unknownResultSetMapping.getMessage(), unknownResultSetMapping );
}
} }
catch ( RuntimeException e ) { catch ( RuntimeException e ) {
throw convert( e ); throw convert( e );