HHH-12129 - Fix expected exceptions on various Query methods

This commit is contained in:
Steve Ebersole 2018-01-10 15:04:23 -06:00
parent f8f1241c2b
commit f0ed669bc1
2 changed files with 47 additions and 2 deletions

View File

@ -687,6 +687,7 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
@Override
@SuppressWarnings("unchecked")
public <T> QueryParameter<T> getParameter(String name, Class<T> type) {
getProducer().checkOpen( false );
try {
final QueryParameter parameter = getParameterMetadata().getQueryParameter( name );
if ( !parameter.getParameterType().isAssignableFrom( type ) ) {

View File

@ -6,6 +6,8 @@
*/
package org.hibernate.test.jpa.compliance.tck2_2;
import javax.persistence.Parameter;
import org.hibernate.Session;
import org.hibernate.query.Query;
@ -55,7 +57,7 @@ public class ClosedManagerTests extends AbstractJPATest {
}
@Test
public void testQuerySetParameter() {
public void testQuerySetPositionalParameter() {
final Session session = sessionFactory().openSession();
final Query qry = session.createQuery( "select i from Item i where i.id = ?1" );
@ -72,7 +74,24 @@ public class ClosedManagerTests extends AbstractJPATest {
}
@Test
public void testQueryGetParameter() {
public void testQuerySetNamedParameter() {
final Session session = sessionFactory().openSession();
final Query qry = session.createQuery( "select i from Item i where i.id = :id" );
session.close();
assertThat( session.isOpen(), CoreMatchers.is ( false ) );
try {
qry.setParameter( "id", 1 );
fail( "Expecting call to fail" );
}
catch (IllegalStateException expected) {
}
}
@Test
public void testQueryGetPositionalParameter() {
final Session session = sessionFactory().openSession();
final Query qry = session.createQuery( "select i from Item i where i.id = ?1" );
@ -95,4 +114,29 @@ public class ClosedManagerTests extends AbstractJPATest {
catch (IllegalStateException expected) {
}
}
@Test
public void testQueryGetNamedParameter() {
final Session session = sessionFactory().openSession();
final Query qry = session.createQuery( "select i from Item i where i.id = :id" );
qry.setParameter( "id", 1 );
session.close();
assertThat( session.isOpen(), CoreMatchers.is ( false ) );
try {
qry.getParameter( "id" );
fail( "Expecting call to fail" );
}
catch (IllegalStateException expected) {
}
try {
qry.getParameter( "id", Long.class );
fail( "Expecting call to fail" );
}
catch (IllegalStateException expected) {
}
}
}