Search in sources :

Example 1 with NativeQuery

use of org.hibernate.query.NativeQuery in project hibernate-orm by hibernate.

the class NativeQueryOrdinalParametersTest method testConflictWithSessionNativeQuery.

@Test
@TestForIssue(jiraKey = "HHH-11121")
public void testConflictWithSessionNativeQuery() {
    EntityManager em = getOrCreateEntityManager();
    final String sqlString = "SELECT * FROM GAME g WHERE title = ?";
    try {
        NativeQuery sqlQuery = em.unwrap(Session.class).createSQLQuery(sqlString);
        sqlQuery.setString(1, "Super Mario Brothers").setCacheable(true);
        List results = sqlQuery.list();
        assertEquals(1, results.size());
        NativeQueryImplementor query = (NativeQueryImplementor) em.createNativeQuery(sqlString);
        query.setString(1, "Super Mario Brothers");
        List list = query.list();
        assertEquals(1, list.size());
        sqlQuery = em.unwrap(Session.class).createSQLQuery(sqlString);
        sqlQuery.setString(1, "Super Mario Brothers").setCacheable(true);
        results = sqlQuery.list();
        assertEquals(1, results.size());
        query.setString(1, "Super Mario Brothers");
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) NativeQueryImplementor(org.hibernate.query.spi.NativeQueryImplementor) NativeQuery(org.hibernate.query.NativeQuery) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with NativeQuery

use of org.hibernate.query.NativeQuery in project hibernate-orm by hibernate.

the class QueryTimeOutTest method testCreateNativeQuerySetTimeout.

@Test
@TestForIssue(jiraKey = "HHH-12075")
public void testCreateNativeQuerySetTimeout() {
    doInHibernate(this::sessionFactory, session -> {
        NativeQuery query = session.createNativeQuery(QUERY);
        query.setTimeout(123);
        query.executeUpdate();
        try {
            verify(CONNECTION_PROVIDER.getPreparedStatement(QUERY), times(1)).setQueryTimeout(123);
        } catch (SQLException ex) {
            fail("should not have thrown exception");
        }
    });
}
Also used : NativeQuery(org.hibernate.query.NativeQuery) SQLException(java.sql.SQLException) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with NativeQuery

use of org.hibernate.query.NativeQuery in project hibernate-orm by hibernate.

the class QueryTimeOutTest method testCreateNativeQuerySetTimeoutHint.

@Test
@TestForIssue(jiraKey = "HHH-12075")
public void testCreateNativeQuerySetTimeoutHint() {
    doInHibernate(this::sessionFactory, session -> {
        NativeQuery query = session.createNativeQuery(QUERY);
        query.setHint(QueryHints.SPEC_HINT_TIMEOUT, 123000);
        query.executeUpdate();
        try {
            verify(CONNECTION_PROVIDER.getPreparedStatement(QUERY), times(1)).setQueryTimeout(123);
        } catch (SQLException ex) {
            fail("should not have thrown exception");
        }
    });
}
Also used : NativeQuery(org.hibernate.query.NativeQuery) SQLException(java.sql.SQLException) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 4 with NativeQuery

use of org.hibernate.query.NativeQuery in project hibernate-orm by hibernate.

the class QueryTimeOutTest method testCreateSQLQuerySetTimeout.

@Test
@TestForIssue(jiraKey = "HHH-12075")
public void testCreateSQLQuerySetTimeout() {
    doInHibernate(this::sessionFactory, session -> {
        NativeQuery query = session.createSQLQuery(QUERY);
        query.setTimeout(123);
        query.executeUpdate();
        try {
            verify(CONNECTION_PROVIDER.getPreparedStatement(QUERY), times(1)).setQueryTimeout(123);
        } catch (SQLException ex) {
            fail("should not have thrown exception");
        }
    });
}
Also used : NativeQuery(org.hibernate.query.NativeQuery) SQLException(java.sql.SQLException) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with NativeQuery

use of org.hibernate.query.NativeQuery in project hibernate-orm by hibernate.

the class QueryTimeOutTest method testCreateSQLQuerySetTimeoutHint.

@Test
@TestForIssue(jiraKey = "HHH-12075")
public void testCreateSQLQuerySetTimeoutHint() {
    doInHibernate(this::sessionFactory, session -> {
        NativeQuery query = session.createSQLQuery(QUERY);
        query.setHint(QueryHints.SPEC_HINT_TIMEOUT, 123000);
        query.executeUpdate();
        try {
            verify(CONNECTION_PROVIDER.getPreparedStatement(QUERY), times(1)).setQueryTimeout(123);
        } catch (SQLException ex) {
            fail("should not have thrown exception");
        }
    });
}
Also used : NativeQuery(org.hibernate.query.NativeQuery) SQLException(java.sql.SQLException) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

NativeQuery (org.hibernate.query.NativeQuery)27 Test (org.junit.Test)8 TestForIssue (org.hibernate.testing.TestForIssue)6 SQLException (java.sql.SQLException)4 Collections.singletonList (java.util.Collections.singletonList)4 HibernateException (org.hibernate.HibernateException)4 DAOException (org.jbei.ice.storage.DAOException)4 Session (org.hibernate.Session)3 Group (org.jbei.ice.storage.model.Group)3 List (java.util.List)2 EntityManager (javax.persistence.EntityManager)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 RObject (com.evolveum.midpoint.repo.sql.data.common.RObject)1 QueryEngine (com.evolveum.midpoint.repo.sql.query.QueryEngine)1 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)1 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)1 ResultHandler (com.evolveum.midpoint.schema.ResultHandler)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)1 ArrayList (java.util.ArrayList)1