Search in sources :

Example 16 with QueryParameterBindings

use of org.hibernate.query.spi.QueryParameterBindings in project hibernate-orm by hibernate.

the class ParameterTests method testNarrowingTemporalPrecision.

@Test
public void testNarrowingTemporalPrecision() {
    try (Session session = sessionFactory().openSession()) {
        final Query query = session.createQuery("select p.id from Person p where p.dob between :start and :end");
        query.setParameter("start", Instant.now().minus(7, ChronoUnit.DAYS), TemporalType.DATE);
        query.setParameter("end", Instant.now().plus(7, ChronoUnit.DAYS), TemporalType.DATE);
        final QueryParameterBindings bindings = ((DomainQueryExecutionContext) query).getQueryParameterBindings();
        final QueryParameterBinding<?> startBinding = bindings.getBinding("start");
        assertThat(startBinding.getExplicitTemporalPrecision(), equalTo(TemporalType.DATE));
        final QueryParameterBinding<?> endBinding = bindings.getBinding("end");
        assertThat(endBinding.getExplicitTemporalPrecision(), equalTo(TemporalType.DATE));
    }
}
Also used : Query(org.hibernate.query.Query) QueryParameterBindings(org.hibernate.query.spi.QueryParameterBindings) Session(org.hibernate.Session) DomainQueryExecutionContext(org.hibernate.query.spi.DomainQueryExecutionContext) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Example 17 with QueryParameterBindings

use of org.hibernate.query.spi.QueryParameterBindings in project hibernate-orm by hibernate.

the class ParameterTests method testWideningTemporalPrecision.

@Test
public void testWideningTemporalPrecision() {
    try (Session session = sessionFactory().openSession()) {
        final Query query = session.createQuery("select p.id from Person p where p.anniversary between :start and :end");
        query.setParameter("start", Date.from(Instant.now().minus(7, ChronoUnit.DAYS)), TemporalType.TIMESTAMP);
        query.setParameter("end", Date.from(Instant.now().plus(7, ChronoUnit.DAYS)), TemporalType.TIMESTAMP);
        final QueryParameterBindings bindings = ((DomainQueryExecutionContext) query).getQueryParameterBindings();
        final QueryParameterBinding<?> startBinding = bindings.getBinding("start");
        assertThat(startBinding.getExplicitTemporalPrecision(), equalTo(TemporalType.TIMESTAMP));
        final QueryParameterBinding<?> endBinding = bindings.getBinding("end");
        assertThat(endBinding.getExplicitTemporalPrecision(), equalTo(TemporalType.TIMESTAMP));
    }
}
Also used : Query(org.hibernate.query.Query) QueryParameterBindings(org.hibernate.query.spi.QueryParameterBindings) Session(org.hibernate.Session) DomainQueryExecutionContext(org.hibernate.query.spi.DomainQueryExecutionContext) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

QueryParameterBindings (org.hibernate.query.spi.QueryParameterBindings)17 JdbcParameterBindingsImpl (org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl)14 JdbcParameterBindings (org.hibernate.sql.exec.spi.JdbcParameterBindings)14 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)13 QueryOptions (org.hibernate.query.spi.QueryOptions)12 Callback (org.hibernate.sql.exec.spi.Callback)12 ExecutionContext (org.hibernate.sql.exec.spi.ExecutionContext)12 JdbcSelect (org.hibernate.sql.exec.spi.JdbcSelect)12 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)10 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)10 SqlAstTranslatorFactory (org.hibernate.sql.ast.SqlAstTranslatorFactory)10 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)8 JdbcParameter (org.hibernate.sql.ast.tree.expression.JdbcParameter)6 SelectStatement (org.hibernate.sql.ast.tree.select.SelectStatement)6 ArrayList (java.util.ArrayList)5 EntityKey (org.hibernate.engine.spi.EntityKey)4 SubselectFetch (org.hibernate.engine.spi.SubselectFetch)4 LoadingEntityEntry (org.hibernate.sql.results.graph.entity.LoadingEntityEntry)4 HibernateException (org.hibernate.HibernateException)3 CollectionKey (org.hibernate.engine.spi.CollectionKey)3