Search in sources :

Example 6 with RequiresDialect

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();
    });
}
Also used : HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.jupiter.api.Test) RequiresDialect(org.hibernate.testing.orm.junit.RequiresDialect)

Example 7 with RequiresDialect

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();
    });
}
Also used : HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) BasicEntity(org.hibernate.testing.orm.domain.gambit.BasicEntity) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.jupiter.api.Test) RequiresDialect(org.hibernate.testing.orm.junit.RequiresDialect)

Example 8 with RequiresDialect

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();
            }
        }
    });
}
Also used : Transaction(org.hibernate.Transaction) Test(org.junit.jupiter.api.Test) RequiresDialect(org.hibernate.testing.orm.junit.RequiresDialect)

Example 9 with RequiresDialect

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);
    });
}
Also used : Date(java.util.Date) BaseSessionFactoryFunctionalTest(org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest) Test(org.junit.jupiter.api.Test) FailureExpected(org.hibernate.testing.orm.junit.FailureExpected) RequiresDialect(org.hibernate.testing.orm.junit.RequiresDialect)

Example 10 with RequiresDialect

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 = ?");
    });
}
Also used : TypedQuery(jakarta.persistence.TypedQuery) Query(jakarta.persistence.Query) NamedNativeQuery(org.hibernate.annotations.NamedNativeQuery) NamedQuery(org.hibernate.annotations.NamedQuery) Test(org.junit.jupiter.api.Test) RequiresDialect(org.hibernate.testing.orm.junit.RequiresDialect)

Aggregations

RequiresDialect (org.hibernate.testing.orm.junit.RequiresDialect)12 Test (org.junit.jupiter.api.Test)12 Query (jakarta.persistence.Query)5 TestForIssue (org.hibernate.testing.TestForIssue)4 TypedQuery (jakarta.persistence.TypedQuery)3 NamedNativeQuery (org.hibernate.annotations.NamedNativeQuery)3 NamedQuery (org.hibernate.annotations.NamedQuery)3 NativeQuery (org.hibernate.query.NativeQuery)2 HibernateCriteriaBuilder (org.hibernate.query.criteria.HibernateCriteriaBuilder)2 SkipForDialect (org.hibernate.testing.SkipForDialect)2 BasicEntity (org.hibernate.testing.orm.domain.gambit.BasicEntity)2 Clob (java.sql.Clob)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Stream (java.util.stream.Stream)1 Transaction (org.hibernate.Transaction)1 BaseSessionFactoryFunctionalTest (org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest)1