Search in sources :

Example 6 with SqmTranslatorFactory

use of org.hibernate.query.sqm.sql.SqmTranslatorFactory in project hibernate-orm by hibernate.

the class EntityJoinTest method testNoImpliedJoinGeneratedForEqualityComparison.

@Test
@TestForIssue(jiraKey = "HHH-11538")
public void testNoImpliedJoinGeneratedForEqualityComparison(SessionFactoryScope scope) {
    final String qry = "select r.id, cust.name " + "from FinancialRecord r " + "	join Customer cust on r.customer = cust" + "   order by r.id";
    scope.inTransaction((session) -> {
        final SessionFactoryImplementor factory = scope.getSessionFactory();
        final EntityMappingType customerEntityDescriptor = factory.getRuntimeMetamodels().getMappingMetamodel().findEntityDescriptor(Customer.class);
        final QueryEngine queryEngine = factory.getQueryEngine();
        final HqlTranslator hqlTranslator = queryEngine.getHqlTranslator();
        final SqmTranslatorFactory sqmTranslatorFactory = queryEngine.getSqmTranslatorFactory();
        final SqmStatement<Object> sqm = hqlTranslator.translate(qry);
        final SqmTranslator<SelectStatement> selectTranslator = sqmTranslatorFactory.createSelectTranslator((SqmSelectStatement<?>) sqm, QueryOptions.NONE, DomainParameterXref.empty(), QueryParameterBindings.NO_PARAM_BINDINGS, LoadQueryInfluencers.NONE, factory, true);
        final SqmTranslation<SelectStatement> sqmTranslation = selectTranslator.translate();
        final SelectStatement sqlAst = sqmTranslation.getSqlAst();
        final List<TableGroup> roots = sqlAst.getQuerySpec().getFromClause().getRoots();
        assertThat(roots.size(), is(1));
        final TableGroup rootTableGroup = roots.get(0);
        assertThat(rootTableGroup.getTableGroupJoins().size(), is(1));
        final TableGroupJoin tableGroupJoin = rootTableGroup.getTableGroupJoins().get(0);
        assertThat(tableGroupJoin.getJoinedGroup().getModelPart(), is(customerEntityDescriptor));
    });
}
Also used : TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) QueryEngine(org.hibernate.query.spi.QueryEngine) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) SqmSelectStatement(org.hibernate.query.sqm.tree.select.SqmSelectStatement) SelectStatement(org.hibernate.sql.ast.tree.select.SelectStatement) HqlTranslator(org.hibernate.query.hql.HqlTranslator) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) SqmTranslatorFactory(org.hibernate.query.sqm.sql.SqmTranslatorFactory) Test(org.junit.jupiter.api.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 7 with SqmTranslatorFactory

use of org.hibernate.query.sqm.sql.SqmTranslatorFactory in project hibernate-orm by hibernate.

the class AbstractResultTests method interpret.

protected SelectStatement interpret(String hql, QueryParameterBindings parameterBindings, SessionFactoryImplementor sessionFactory) {
    final QueryEngine queryEngine = sessionFactory.getQueryEngine();
    final SqmSelectStatement<?> sqm = (SqmSelectStatement<?>) queryEngine.getHqlTranslator().translate(hql);
    final SqmTranslatorFactory sqmTranslatorFactory = queryEngine.getSqmTranslatorFactory();
    final SqmTranslator<SelectStatement> sqmConverter = sqmTranslatorFactory.createSelectTranslator(sqm, QueryOptions.NONE, DomainParameterXref.from(sqm), parameterBindings, LoadQueryInfluencers.NONE, sessionFactory, true);
    return sqmConverter.translate().getSqlAst();
}
Also used : SqmSelectStatement(org.hibernate.query.sqm.tree.select.SqmSelectStatement) SelectStatement(org.hibernate.sql.ast.tree.select.SelectStatement) SqmSelectStatement(org.hibernate.query.sqm.tree.select.SqmSelectStatement) QueryEngine(org.hibernate.query.spi.QueryEngine) SqmTranslatorFactory(org.hibernate.query.sqm.sql.SqmTranslatorFactory)

Aggregations

SqmTranslatorFactory (org.hibernate.query.sqm.sql.SqmTranslatorFactory)7 QueryEngine (org.hibernate.query.spi.QueryEngine)6 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)5 SqmSelectStatement (org.hibernate.query.sqm.tree.select.SqmSelectStatement)3 SelectStatement (org.hibernate.sql.ast.tree.select.SelectStatement)3 HqlTranslator (org.hibernate.query.hql.HqlTranslator)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Dialect (org.hibernate.dialect.Dialect)1 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 NativeQueryInterpreter (org.hibernate.engine.query.spi.NativeQueryInterpreter)1 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)1 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)1 MappingModelExpressible (org.hibernate.metamodel.mapping.MappingModelExpressible)1 StandardHqlTranslator (org.hibernate.query.hql.internal.StandardHqlTranslator)1 SqmCreationOptions (org.hibernate.query.hql.spi.SqmCreationOptions)1 QueryParameterImplementor (org.hibernate.query.spi.QueryParameterImplementor)1 SqmFunctionDescriptor (org.hibernate.query.sqm.function.SqmFunctionDescriptor)1