Search in sources :

Example 1 with CreditCard

use of org.hibernate.orm.test.jpa.metamodel.CreditCard in project hibernate-orm by hibernate.

the class PredicateTest method testExplicitBuilderBooleanHandling.

@Test
public void testExplicitBuilderBooleanHandling() {
    // just checking syntax of the resulting query
    EntityManager em = getOrCreateEntityManager();
    em.getTransaction().begin();
    // note : these may fail on various matrix db jobs depending on how the dialect handles booleans
    {
        CriteriaQuery<CreditCard> criteriaQuery = builder.createQuery(CreditCard.class);
        Root<CreditCard> root = criteriaQuery.from(CreditCard.class);
        criteriaQuery.where(builder.isFalse(root.get(CreditCard_.approved)));
        em.createQuery(criteriaQuery).getResultList();
    }
    {
        CriteriaQuery<Order> criteriaQuery = builder.createQuery(Order.class);
        Root<Order> root = criteriaQuery.from(Order.class);
        criteriaQuery.where(builder.isFalse(root.get(Order_.creditCard).get(CreditCard_.approved)));
        em.createQuery(criteriaQuery).getResultList();
    }
    em.getTransaction().commit();
    em.close();
}
Also used : Order(org.hibernate.orm.test.jpa.metamodel.Order) EntityManager(jakarta.persistence.EntityManager) Root(jakarta.persistence.criteria.Root) CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) CreditCard(org.hibernate.orm.test.jpa.metamodel.CreditCard) AbstractMetamodelSpecificTest(org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest) Test(org.junit.jupiter.api.Test)

Aggregations

EntityManager (jakarta.persistence.EntityManager)1 CriteriaQuery (jakarta.persistence.criteria.CriteriaQuery)1 Root (jakarta.persistence.criteria.Root)1 AbstractMetamodelSpecificTest (org.hibernate.orm.test.jpa.metamodel.AbstractMetamodelSpecificTest)1 CreditCard (org.hibernate.orm.test.jpa.metamodel.CreditCard)1 Order (org.hibernate.orm.test.jpa.metamodel.Order)1 Test (org.junit.jupiter.api.Test)1