use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class BasicCriteriaExecutionTests method testExecutingBasicCriteriaQueryParameterPredicate.
// Doing ... where ? = ? ... is only allowed in a few DBs. Since this is useless, we don't bother to emulate this
@Test
@RequiresDialect(H2Dialect.class)
@SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't support comparing parameters against each other")
public void testExecutingBasicCriteriaQueryParameterPredicate(SessionFactoryScope scope) {
scope.inStatelessTransaction(session -> {
final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
final CriteriaQuery<Object> criteria = criteriaBuilder.createQuery();
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
criteria.select(root);
final ParameterExpression<Integer> param = criteriaBuilder.parameter(Integer.class);
criteria.where(criteriaBuilder.equal(param, param));
session.createQuery(criteria).setParameter(param, 1).list();
});
}
use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class BasicCriteriaExecutionTests method testExecutingBasicCriteriaQueryParameterPredicateInStatelessSession.
// Doing ... where ? = ? ... is only allowed in a few DBs. Since this is useless, we don't bother to emulate this
@Test
@RequiresDialect(H2Dialect.class)
@SkipForDialect(value = DerbyDialect.class, comment = "Derby doesn't support comparing parameters against each other")
public void testExecutingBasicCriteriaQueryParameterPredicateInStatelessSession(SessionFactoryScope scope) {
scope.inStatelessTransaction(session -> {
final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
final CriteriaQuery<Object> criteria = criteriaBuilder.createQuery();
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
criteria.select(root);
final ParameterExpression<Integer> param = criteriaBuilder.parameter(Integer.class);
criteria.where(criteriaBuilder.equal(param, param));
session.createQuery(criteria).setParameter(param, 1).list();
});
}
use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class IndexedCollectionTest method testComponentSubPropertyMapKey.
@Test
@RequiresDialect(value = HSQLDialect.class)
@RequiresDialect(value = H2Dialect.class)
public void testComponentSubPropertyMapKey(SessionFactoryScope scope) {
scope.inSession(s -> {
try {
Transaction tx;
tx = s.beginTransaction();
AddressBook book = new AddressBook();
book.setOwner("Emmanuel");
AddressEntryPk helene = new AddressEntryPk("Helene", "Michau");
AddressEntry heleneEntry = new AddressEntry();
heleneEntry.setBook(book);
heleneEntry.setCity("Levallois");
heleneEntry.setStreet("Louis Blanc");
heleneEntry.setPerson(helene);
AddressEntryPk primeMinister = new AddressEntryPk("Dominique", "Villepin");
AddressEntry primeMinisterEntry = new AddressEntry();
primeMinisterEntry.setBook(book);
primeMinisterEntry.setCity("Paris");
primeMinisterEntry.setStreet("Hotel Matignon");
primeMinisterEntry.setPerson(primeMinister);
book.getEntries().put(helene, heleneEntry);
book.getEntries().put(primeMinister, primeMinisterEntry);
s.persist(book);
s.flush();
s.clear();
book = s.get(AddressBook.class, book.getId());
assertEquals(2, book.getLastNameEntries().size());
assertEquals(heleneEntry.getCity(), book.getLastNameEntries().get("Michau").getCity());
AddressEntryPk fake = new AddressEntryPk("Fake", "Fake");
book.getEntries().put(fake, primeMinisterEntry);
s.flush();
s.clear();
book = s.get(AddressBook.class, book.getId());
assertEquals(2, book.getEntries().size());
assertNull(book.getEntries().get(fake));
s.delete(book);
tx.rollback();
} catch (Exception e) {
if (s.getTransaction().isActive()) {
s.getTransaction().rollback();
}
}
});
}
use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class ComponentTest method testComponentQueryMethodNoParensFailureExpected.
@Test
@RequiresDialect(value = SybaseASEDialect.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.
inTransaction(s -> {
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 = (current_timestamp, 'steve')").list();
s.delete(emp);
});
}
use of org.hibernate.testing.orm.junit.RequiresDialect in project hibernate-orm by hibernate.
the class NamedQueryCommentTest method testUpdateNamedNativeQueryWithQueryHintUsingOracle.
@Test
@RequiresDialect(value = OracleDialect.class)
public void testUpdateNamedNativeQueryWithQueryHintUsingOracle(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 /*+ INDEX (game idx_game_id) */ game set title = ? where id = ?");
});
}
Aggregations