Search in sources :

Example 41 with RequiresDialect

use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.

the class NamedQueryCommentTest method testSelectNamedNativeQueryWithQueryHintUsingIndex.

@Test
@RequiresDialect(MySQLDialect.class)
@RequiresDialect(H2Dialect.class)
public void testSelectNamedNativeQueryWithQueryHintUsingIndex() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        connectionProvider.clear();
        Query query = entityManager.createNamedQuery("SelectNamedQuery");
        query.setParameter("title", GAME_TITLES[0]);
        query.unwrap(org.hibernate.query.Query.class).addQueryHint("idx_game_id");
        List<Game> list = query.getResultList();
        assertEquals(1, list.size());
        assertEquals(1, connectionProvider.getPreparedStatements().size());
        assertNotNull(connectionProvider.getPreparedStatement("/* COMMENT_SELECT_INDEX_game_title */ select namedquery0_.id as id1_0_, namedquery0_.title as title2_0_ from game namedquery0_  USE INDEX (idx_game_id) where namedquery0_.title=?"));
    });
}
Also used : TypedQuery(javax.persistence.TypedQuery) NamedNativeQuery(org.hibernate.annotations.NamedNativeQuery) Query(javax.persistence.Query) NamedQuery(org.hibernate.annotations.NamedQuery) Test(org.junit.Test) RequiresDialect(org.hibernate.testing.RequiresDialect)

Aggregations

RequiresDialect (org.hibernate.testing.RequiresDialect)41 Test (org.junit.Test)39 Session (org.hibernate.Session)18 TestForIssue (org.hibernate.testing.TestForIssue)13 RequiresDialectFeature (org.hibernate.testing.RequiresDialectFeature)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExecutionException (java.util.concurrent.ExecutionException)6 FutureTask (java.util.concurrent.FutureTask)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Transaction (org.hibernate.Transaction)6 HashMap (java.util.HashMap)5 Query (javax.persistence.Query)5 Phone (org.hibernate.userguide.model.Phone)5 LockTimeoutException (javax.persistence.LockTimeoutException)4 List (java.util.List)3 EntityManager (javax.persistence.EntityManager)3 TypedQuery (javax.persistence.TypedQuery)3 LockOptions (org.hibernate.LockOptions)3 NamedNativeQuery (org.hibernate.annotations.NamedNativeQuery)3 NamedQuery (org.hibernate.annotations.NamedQuery)3