Search in sources :

Example 1 with SkipForDialect

use of org.hibernate.testing.orm.junit.SkipForDialect in project hibernate-orm by hibernate.

the class CriteriaLiteralInSelectExpressionTest method testStringLiteral2.

@Test
@TestForIssue(jiraKey = "HHH-9021")
@SkipForDialect(dialectClass = OracleDialect.class)
@SkipForDialect(dialectClass = DB2Dialect.class)
@SkipForDialect(dialectClass = SQLServerDialect.class)
@SkipForDialect(dialectClass = SybaseDialect.class)
@SkipForDialect(dialectClass = AbstractHANADialect.class)
public void testStringLiteral2(EntityManagerFactoryScope scope) {
    scope.inTransaction(entityManager -> {
        final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
        final CriteriaQuery<Tuple> criteriaQuery = builder.createQuery(Tuple.class);
        criteriaQuery.from(MyEntity.class);
        criteriaQuery.multiselect(builder.equal(builder.literal(1), builder.literal(2)));
        final TypedQuery<Tuple> typedQuery = entityManager.createQuery(criteriaQuery);
        final List<Tuple> results = typedQuery.getResultList();
        assertThat(results.size(), is(1));
        assertThat(results.get(0).getElements().size(), is(1));
        assertThat(results.get(0).get(0), is(false));
    });
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) Tuple(jakarta.persistence.Tuple) SkipForDialect(org.hibernate.testing.orm.junit.SkipForDialect) Test(org.junit.jupiter.api.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with SkipForDialect

use of org.hibernate.testing.orm.junit.SkipForDialect in project hibernate-orm by hibernate.

the class PredicateTest method testQuotientConversion.

@Test
@TestForIssue(jiraKey = "HHH-5803")
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "https://github.com/cockroachdb/cockroach/issues/41943")
public void testQuotientConversion() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
    Root<Order> orderRoot = orderCriteria.from(Order.class);
    Long longValue = 999999999L;
    Path<Double> doublePath = orderRoot.get(Order_.totalPrice);
    Path<Integer> integerPath = orderRoot.get(Order_.customer).get(Customer_.age);
    orderCriteria.select(orderRoot);
    Predicate p = builder.ge(builder.quot(integerPath, doublePath), longValue);
    orderCriteria.where(p);
    List<Order> orders = em.createQuery(orderCriteria).getResultList();
    assertTrue(orders.size() == 0);
    em.getTransaction().commit();
    em.close();
}
Also used : Order(org.hibernate.orm.test.jpa.metamodel.Order) EntityManager(jakarta.persistence.EntityManager) Predicate(jakarta.persistence.criteria.Predicate) SkipForDialect(org.hibernate.testing.orm.junit.SkipForDialect) AbstractMetamodelSpecificTest(org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest) Test(org.junit.jupiter.api.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with SkipForDialect

use of org.hibernate.testing.orm.junit.SkipForDialect in project hibernate-orm by hibernate.

the class PredicateTest method testByteArray.

/**
 * Check predicate for field which has simple byte array type (byte[]).
 */
@Test
@JiraKey("HHH-10603")
@SkipForDialect(dialectClass = OracleDialect.class, majorVersion = 12, reason = "Oracle12cDialect uses blob to store byte arrays and it's not possible to compare blobs with simple equality operators.")
public void testByteArray() {
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    CriteriaQuery<Order> orderCriteria = builder.createQuery(Order.class);
    Root<Order> orderRoot = orderCriteria.from(Order.class);
    orderCriteria.select(orderRoot);
    Predicate p = builder.equal(orderRoot.get("number"), new byte[] { '1', '2' });
    orderCriteria.where(p);
    List<Order> orders = em.createQuery(orderCriteria).getResultList();
    assertTrue(orders.size() == 0);
    em.getTransaction().commit();
    em.close();
}
Also used : Order(org.hibernate.orm.test.jpa.metamodel.Order) EntityManager(jakarta.persistence.EntityManager) Predicate(jakarta.persistence.criteria.Predicate) SkipForDialect(org.hibernate.testing.orm.junit.SkipForDialect) AbstractMetamodelSpecificTest(org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest) Test(org.junit.jupiter.api.Test) JiraKey(org.hibernate.testing.orm.junit.JiraKey)

Example 4 with SkipForDialect

use of org.hibernate.testing.orm.junit.SkipForDialect in project hibernate-orm by hibernate.

the class StatelessSessionQueryTest method testNewQueryApis.

@Test
@TestForIssue(jiraKey = "HHH-13194")
@SkipForDialect(dialectClass = AbstractHANADialect.class, matchSubTypes = true, reason = " HANA doesn't support tables consisting of only a single auto-generated column")
public void testNewQueryApis(SessionFactoryScope scope) {
    final String queryString = "from Contact c join fetch c.org o join fetch o.country";
    scope.inStatelessSession(session -> {
        Query query = session.createQuery(queryString);
        assertEquals(1, query.getResultList().size());
        query = session.getNamedQuery(Contact.class.getName() + ".contacts");
        assertEquals(1, query.getResultList().size());
        NativeQuery sqlQuery = session.createNativeQuery("select id from Contact");
        assertEquals(1, sqlQuery.getResultList().size());
    });
}
Also used : NativeQuery(org.hibernate.query.NativeQuery) Query(org.hibernate.query.Query) NativeQuery(org.hibernate.query.NativeQuery) SkipForDialect(org.hibernate.testing.orm.junit.SkipForDialect) Test(org.junit.jupiter.api.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 5 with SkipForDialect

use of org.hibernate.testing.orm.junit.SkipForDialect in project hibernate-orm by hibernate.

the class ManyToManySizeTest method testSizeAsSelectExpressionWithInnerJoin.

@Test
@SkipForDialect(dialectClass = DerbyDialect.class, reason = "Derby doesn't see that the subquery is functionally dependent")
public void testSizeAsSelectExpressionWithInnerJoin(SessionFactoryScope scope) {
    scope.inTransaction((session) -> {
        final List results = session.createQuery("select new org.hibernate.orm.test.query.hql.size.ManyToManySizeTest$CompanyDto(" + " c.id, c.name, size( c.customers ) )" + " from Company c inner join c.customers cu" + " group by c.id, c.name" + " order by c.id").list();
        assertThat(results.size(), is(2));
        final CompanyDto companyDto1 = (CompanyDto) results.get(0);
        assertThat(companyDto1.getId(), is(1));
        assertThat(companyDto1.getName(), is("Company 1"));
        assertThat(companyDto1.getSizeCustomer(), is(1));
        final CompanyDto companyDto2 = (CompanyDto) results.get(1);
        assertThat(companyDto2.getId(), is(2));
        assertThat(companyDto2.getName(), is("Company 2"));
        assertThat(companyDto2.getSizeCustomer(), is(2));
    });
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) SkipForDialect(org.hibernate.testing.orm.junit.SkipForDialect) Test(org.junit.jupiter.api.Test)

Aggregations

SkipForDialect (org.hibernate.testing.orm.junit.SkipForDialect)33 Test (org.junit.jupiter.api.Test)33 ArrayList (java.util.ArrayList)15 List (java.util.List)14 TestForIssue (org.hibernate.testing.TestForIssue)5 RequiresDialectFeature (org.hibernate.testing.orm.junit.RequiresDialectFeature)5 EntityManager (jakarta.persistence.EntityManager)4 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)4 ScrollableResults (org.hibernate.ScrollableResults)4 AbstractMetamodelSpecificTest (org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest)4 Predicate (jakarta.persistence.criteria.Predicate)3 Order (org.hibernate.orm.test.jpa.metamodel.Order)3 Query (org.hibernate.query.Query)3 Customer (org.hibernate.orm.test.jpa.metamodel.Customer)2 NativeQuery (org.hibernate.query.NativeQuery)2 JiraKey (org.hibernate.testing.orm.junit.JiraKey)2 Query (jakarta.persistence.Query)1 Tuple (jakarta.persistence.Tuple)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1