HHH-17499 Fix tuple length check for positional parameters

This commit is contained in:
Marco Belladelli 2023-12-11 14:54:54 +01:00 committed by Christian Beikov
parent 0440dd5a8c
commit d3027907c2
3 changed files with 38 additions and 5 deletions

View File

@ -69,4 +69,9 @@ public abstract class AbstractSqmParameter<T> extends AbstractSqmExpression<T> i
public Class<T> getParameterType() {
return this.getNodeType().getExpressibleJavaType().getJavaTypeClass();
}
@Override
public Integer getTupleLength() {
return null;
}
}

View File

@ -88,9 +88,4 @@ public class SqmNamedParameter<T> extends AbstractSqmParameter<T> {
? getName().compareTo( ( (SqmNamedParameter<?>) anotherParameter ).getName() )
: -1;
}
@Override
public Integer getTupleLength() {
return null;
}
}

View File

@ -11,6 +11,7 @@ import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.testing.orm.domain.gambit.EmbeddedIdEntity;
import org.hibernate.testing.orm.domain.gambit.EmbeddedIdEntity.EmbeddedIdEntityId;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
@ -120,4 +121,36 @@ public class EmbeddedIdEntityTest {
);
assertThat( statistics.getPrepareStatementCount(), is( 1L ) );
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-17499" )
public void testNamedParameterComparison(SessionFactoryScope scope) {
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
statistics.clear();
scope.inTransaction( session -> {
final EmbeddedIdEntity loaded = session.createQuery(
"select e FROM EmbeddedIdEntity e WHERE e.id = :id",
EmbeddedIdEntity.class
).setParameter( "id", entityId ).getSingleResult();
assertThat( loaded.getData(), is( "test" ) );
assertThat( loaded.getId(), equalTo( entityId ) );
} );
assertThat( statistics.getPrepareStatementCount(), is( 1L ) );
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-17499" )
public void testPositionalParameterComparison(SessionFactoryScope scope) {
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
statistics.clear();
scope.inTransaction( session -> {
final EmbeddedIdEntity loaded = session.createQuery(
"select e FROM EmbeddedIdEntity e WHERE e.id = ?1",
EmbeddedIdEntity.class
).setParameter( 1, entityId ).getSingleResult();
assertThat( loaded.getData(), is( "test" ) );
assertThat( loaded.getId(), equalTo( entityId ) );
} );
assertThat( statistics.getPrepareStatementCount(), is( 1L ) );
}
}