use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class PessimisticWriteLockTimeoutTest method testSkipLocked.
@Test
@RequiresDialect({ Oracle8iDialect.class, PostgreSQL95Dialect.class })
public void testSkipLocked() throws NoSuchFieldException, IllegalAccessException {
Session session = sessionFactory().openSession();
session.beginTransaction();
try {
session.createQuery("select a from A a", A.class).unwrap(org.hibernate.query.Query.class).setLockOptions(new LockOptions(LockMode.PESSIMISTIC_WRITE).setTimeOut(LockOptions.SKIP_LOCKED)).list();
String lockingQuery = sqlStatementInterceptor.getSqlQueries().getLast();
assertTrue(lockingQuery.toLowerCase().contains("skip locked"));
} finally {
session.getTransaction().commit();
session.close();
}
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class OrderByTest method testCriteriaNullsFirstLast.
@Test
@TestForIssue(jiraKey = "HHH-465")
@RequiresDialect(value = { H2Dialect.class, MySQLDialect.class, SQLServer2008Dialect.class }, comment = "By default H2 places NULL values first, so testing 'NULLS LAST' expression. " + "For MySQL and SQL Server 2008 testing overridden Dialect#renderOrderByElement(String, String, String, NullPrecedence) method. " + "MySQL and SQL Server 2008 does not support NULLS FIRST / LAST syntax at the moment, so transforming the expression to 'CASE WHEN ...'.")
public void testCriteriaNullsFirstLast() {
Session session = openSession();
// Populating database with test data.
session.getTransaction().begin();
Zoo zoo1 = new Zoo(null);
Zoo zoo2 = new Zoo("Warsaw ZOO");
session.persist(zoo1);
session.persist(zoo2);
session.getTransaction().commit();
session.clear();
session.getTransaction().begin();
Criteria criteria = session.createCriteria(Zoo.class);
criteria.addOrder(org.hibernate.criterion.Order.asc("name").nulls(NullPrecedence.LAST));
Iterator<Zoo> iterator = (Iterator<Zoo>) criteria.list().iterator();
Assert.assertEquals(zoo2.getName(), iterator.next().getName());
Assert.assertNull(iterator.next().getName());
session.getTransaction().commit();
session.clear();
// Cleanup data.
session.getTransaction().begin();
session.delete(zoo1);
session.delete(zoo2);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class OrderByTest method testNullsFirstLastSpawnMultipleColumns.
@Test
@TestForIssue(jiraKey = "HHH-465")
@RequiresDialect(value = { H2Dialect.class, MySQLDialect.class, SQLServer2008Dialect.class }, comment = "By default H2 places NULL values first, so testing 'NULLS LAST' expression. " + "For MySQL and SQL Server 2008 testing overridden Dialect#renderOrderByElement(String, String, String, NullPrecedence) method. " + "MySQL and SQL Server 2008 does not support NULLS FIRST / LAST syntax at the moment, so transforming the expression to 'CASE WHEN ...'.")
public void testNullsFirstLastSpawnMultipleColumns() {
Session session = openSession();
// Populating database with test data.
session.getTransaction().begin();
Zoo zoo = new Zoo();
zoo.setName("Berlin ZOO");
Visitor visitor1 = new Visitor(null, null);
Visitor visitor2 = new Visitor(null, "Antoniak");
Visitor visitor3 = new Visitor("Lukasz", "Antoniak");
zoo.getVisitors().add(visitor1);
zoo.getVisitors().add(visitor2);
zoo.getVisitors().add(visitor3);
session.save(zoo);
session.save(visitor1);
session.save(visitor2);
session.save(visitor3);
session.getTransaction().commit();
session.clear();
session.getTransaction().begin();
zoo = (Zoo) session.get(Zoo.class, zoo.getId());
Iterator<Visitor> iterator = zoo.getVisitors().iterator();
Assert.assertEquals(3, zoo.getVisitors().size());
Assert.assertEquals(visitor3, iterator.next());
Assert.assertEquals(visitor2, iterator.next());
Assert.assertEquals(visitor1, iterator.next());
session.getTransaction().commit();
session.clear();
// Cleanup data.
session.getTransaction().begin();
session.delete(visitor1);
session.delete(visitor2);
session.delete(visitor3);
session.delete(zoo);
session.getTransaction().commit();
session.close();
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class ComponentTest method testComponentQueryMethodNoParensFailureExpected.
@Test
@RequiresDialect(value = SybaseASE15Dialect.class)
@FailureExpected(jiraKey = "HHH-3150")
public void testComponentQueryMethodNoParensFailureExpected() {
// Sybase should translate "current_timestamp" in HQL to "getdate()";
// This fails currently due to HHH-3510. The following test should be
// deleted and testComponentQueries() should be updated (as noted
// in that test case) when HHH-3510 is fixed.
Session s = openSession();
Transaction t = s.beginTransaction();
Employee emp = new Employee();
emp.setHireDate(new Date());
emp.setPerson(new Person());
emp.getPerson().setName("steve");
emp.getPerson().setDob(new Date());
s.save(emp);
s.createQuery("from Employee e where e.person = ('steve', current_timestamp)").list();
s.delete(emp);
t.commit();
s.close();
}
use of org.hibernate.testing.RequiresDialect in project hibernate-orm by hibernate.
the class SQLTest method test_sql_jpa_entity_associations_query_one_to_many_join_example.
@Test
@RequiresDialect(H2Dialect.class)
@RequiresDialect(Oracle8iDialect.class)
@RequiresDialect(PostgreSQL82Dialect.class)
public void test_sql_jpa_entity_associations_query_one_to_many_join_example() {
doInJPA(this::entityManagerFactory, entityManager -> {
List<Phone> phones = entityManager.createNativeQuery("SELECT * " + "FROM Phone ph " + "JOIN phone_call c ON c.phone_id = ph.id", Phone.class).getResultList();
for (Phone phone : phones) {
List<Call> calls = phone.getCalls();
}
assertEquals(2, phones.size());
});
}
Aggregations