use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class ProcedureCallImplTest method testNoNullPointerExceptionThrown.
@Test
@TestForIssue(jiraKey = "HHH-13644")
@RequiresDialect(H2Dialect.class)
public void testNoNullPointerExceptionThrown(EntityManagerFactoryScope scope) {
scope.inTransaction(em -> {
em.createNativeQuery("CREATE ALIAS GET_RANDOM_VALUE FOR \"java.lang.Math.random\";").executeUpdate();
Query query = em.createStoredProcedureQuery("GET_RANDOM_VALUE");
Stream stream = query.getResultStream();
Assert.assertEquals(1, stream.count());
});
}
use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class LobStringTest method testUsingStringLobAnnotatedPropertyInNativeQuery.
@Test
@TestForIssue(jiraKey = "HHH-11477")
@RequiresDialect(PostgreSQLDialect.class)
public void testUsingStringLobAnnotatedPropertyInNativeQuery(SessionFactoryScope scope) {
scope.inTransaction(session -> {
final List<TestEntity> results = session.createNativeQuery("select te.* " + "from test_entity te " + "where lower(convert_from(lo_get(cast(te.firstLobField as oid)), 'UTF8')) LIKE :value", TestEntity.class).setParameter("value", value1).getResultList();
assertThat(results.size(), is(1));
final TestEntity testEntity = results.get(0);
assertThat(testEntity.getFirstLobField(), is(value1));
assertThat(testEntity.getSecondLobField(), is(value2));
final Clob clobField = testEntity.getClobField();
try {
assertThat(clobField.getSubString(1, (int) clobField.length()), is(value2));
} catch (SQLException e) {
fail(e.getMessage());
}
});
}
use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class NativeSQLQueriesTest method testEscapeColonInSQL.
@Test
@RequiresDialect(value = MySQLDialect.class, majorVersion = 5)
public void testEscapeColonInSQL(SessionFactoryScope scope) throws QueryException {
scope.inTransaction(session -> {
NativeQuery query = session.createNativeQuery("SELECT @row \\:= 1");
List list = query.list();
assertTrue(list.get(0).toString().equals("1"));
});
}
use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class NamedQueryCommentTest method testUpdateNamedNativeQueryWithQueryHintUsingIndex.
@Test
@RequiresDialect(H2Dialect.class)
public void testUpdateNamedNativeQueryWithQueryHintUsingIndex(EntityManagerFactoryScope scope) {
scope.inTransaction(entityManager -> {
statementInspector.clear();
Query query = entityManager.createNamedQuery("UpdateNamedNativeQuery");
query.setParameter("title", GAME_TITLES[0]);
query.setParameter("id", 1L);
query.unwrap(org.hibernate.query.Query.class).addQueryHint("INDEX (game idx_game_id)");
int updateCount = query.executeUpdate();
assertEquals(1, updateCount);
statementInspector.assertExecutedCount(1);
statementInspector.assertExecuted("/* COMMENT_INDEX_game_title */ update game set title = ? where id = ?");
});
}
use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class NativeQueryOrdinalParametersTest method testCteNativeQueryOrdinalParameter.
@Test
@TestForIssue(jiraKey = "HHH-12532")
// Add RequiresDialect be Cockroach version 201
@RequiresDialect(value = PostgreSQLDialect.class, majorVersion = 8, minorVersion = 2)
@RequiresDialect(value = CockroachDialect.class, majorVersion = 20, minorVersion = 1)
public void testCteNativeQueryOrdinalParameter(EntityManagerFactoryScope scope) {
Node root1 = new Node();
root1.setCode("ABC");
Node root2 = new Node();
root2.setCode("DEF");
Node node11 = new Node();
node11.setParent(root1);
Node node21 = new Node();
node21.setParent(root2);
Node node211 = new Node();
node211.setParent(node21);
scope.inTransaction(entityManager -> {
entityManager.persist(root1);
entityManager.persist(root2);
entityManager.persist(node11);
entityManager.persist(node21);
entityManager.persist(node211);
});
scope.inTransaction(entityManager -> {
Query cte = entityManager.createNativeQuery("WITH RECURSIVE CTE(id, parent_id) AS ( " + " SELECT id, parent_id " + " FROM Node " + " WHERE code like ?1 and parent_id is null" + " UNION ALL " + " SELECT child.id, child.parent_id " + " FROM Node child " + " JOIN CTE cte " + " ON cte.id = child.parent_id " + ") SELECT DISTINCT id as integer " + " FROM CTE cte");
List<Long> root1Ids = cte.setParameter(1, "AB%").getResultList();
assertEquals(2, root1Ids.size());
assertTrue(root1Ids.contains(root1.getId()));
assertTrue(root1Ids.contains(node11.getId()));
List<Long> root2Ids = cte.setParameter(1, "DE%").getResultList();
assertEquals(3, root2Ids.size());
assertTrue(root2Ids.contains(root2.getId()));
assertTrue(root2Ids.contains(node21.getId()));
assertTrue(root2Ids.contains(node211.getId()));
});
}
Aggregations