HHH-16347 Add test for issue

This commit is contained in:
Marco Belladelli 2023-04-05 12:11:22 +02:00
parent 46041a138d
commit 6990346506
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
1 changed files with 46 additions and 0 deletions

View File

@ -9,10 +9,14 @@ package org.hibernate.orm.test.query.hql;
import java.util.Date;
import java.util.List;
import org.hibernate.internal.util.ExceptionHelper;
import org.hibernate.query.sqm.ParsingException;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.domain.gambit.EntityOfBasics;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
@ -24,7 +28,10 @@ import org.junit.jupiter.api.Test;
import jakarta.persistence.TypedQuery;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Christian Beikov
@ -165,4 +172,43 @@ public class WindowFunctionTest {
}
);
}
@Test
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsWindowFunctions.class )
@Jira( "https://hibernate.atlassian.net/browse/HHH-16347" )
public void testOrderByAndAlias(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
final TypedQuery<Integer> q = session.createQuery(
"select id from (select id as id, dense_rank() over (order by theInt, id ASC) as ranking" +
" from EntityOfBasics) entity_rank where ranking = :rank",
Integer.class
).setParameter( "rank", 5 );
assertEquals( 4, q.getSingleResult() );
}
);
}
@Test
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsWindowFunctions.class )
@Jira( "https://hibernate.atlassian.net/browse/HHH-16347" )
public void testOrderByAndPositional(SessionFactoryScope scope) {
scope.inTransaction( session -> {
try {
session.createQuery(
"select id from (select id, dense_rank() over (order by theInt, 1 ASC) as ranking from EntityOfBasics) ",
Integer.class
);
fail( "Order-by positional '1' should not be allowed in OVER clause" );
}
catch (Exception e) {
final Throwable rootCause = ExceptionHelper.getRootCause( e );
assertInstanceOf( ParsingException.class, rootCause );
assertEquals(
"Position based order-by is not allowed in OVER or WITHIN GROUP clauses",
rootCause.getMessage()
);
}
} );
}
}