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();
}
}
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");
}
});
}
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");
}
});
}
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");
}
});
}
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");
}
});
}
Aggregations