Search in sources :

Example 11 with CriteriaBuilder

use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.

the class TreatJoinTest method testJoinOnTreatedRoot.

@Test
@TestForIssue(jiraKey = "HHH-10561")
public void testJoinOnTreatedRoot() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        CriteriaQuery<Item> criteria = cb.createQuery(Item.class);
        Root<Item> root = criteria.from(Item.class);
        Root<Book> treatedRoot = cb.treat(root, Book.class);
        criteria.where(cb.equal(treatedRoot.<Book, Author>join("author").<String>get("name"), "Andrea Camilleri"));
        entityManager.createQuery(criteria.select(treatedRoot)).getResultList();
    });
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 12 with CriteriaBuilder

use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.

the class TreatJoinTest method testTreatJoin.

@Test
@TestForIssue(jiraKey = "HHH-8488")
public void testTreatJoin() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        CriteriaQuery<Bid> query = cb.createQuery(Bid.class);
        Root<Bid> bid = query.from(Bid.class);
        Join<Bid, Book> book = cb.treat(bid.join("item"), Book.class);
        query.select(book.get("title"));
        final List<Bid> resultList = entityManager.createQuery(query).getResultList();
        assertThat(resultList.size(), is(2));
    });
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 13 with CriteriaBuilder

use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.

the class TreatJoinTest method testJoinMethodOnATreatedJoin.

@Test
@TestForIssue(jiraKey = "HHH-8488")
public void testJoinMethodOnATreatedJoin() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        CriteriaQuery<Bid> query = cb.createQuery(Bid.class);
        Root<Bid> bid = query.from(Bid.class);
        final Join<Bid, Book> item = bid.join("item");
        final Join<Object, Object> price = item.join("price");
        Join<Bid, Book> book = cb.treat(item, Book.class);
        Join<Book, Author> owner = book.join("author");
        query.select(owner.get("name"));
        query.where(cb.equal(price.get("amount"), 10));
        final List<Bid> resultList = entityManager.createQuery(query).getResultList();
        assertThat(resultList.size(), is(2));
    });
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 14 with CriteriaBuilder

use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.

the class TreatJoinTest method testJoinOnTreatedRootWithJoin.

@Test
@TestForIssue(jiraKey = "HHH-10561")
public void testJoinOnTreatedRootWithJoin() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        CriteriaQuery<Item> criteria = cb.createQuery(Item.class);
        Root<Item> root = criteria.from(Item.class);
        root.join("price");
        Root<Book> treatedRoot = cb.treat(root, Book.class);
        criteria.where(cb.equal(treatedRoot.<Book, Author>join("author").<String>get("name"), "Andrea Camilleri"));
        entityManager.createQuery(criteria.select(treatedRoot)).getResultList();
    });
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 15 with CriteriaBuilder

use of javax.persistence.criteria.CriteriaBuilder in project hibernate-orm by hibernate.

the class TreatKeywordTest method basicTest2.

@Test
public void basicTest2() {
    EntityManager em = getOrCreateEntityManager();
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<Animal> criteria = builder.createQuery(Animal.class);
    Root<Animal> root = criteria.from(Animal.class);
    criteria.select(root);
    criteria.where(builder.equal(builder.treat(root, Human.class).get("name"), "2"));
    em.createQuery(criteria).getResultList();
    em.close();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test)

Aggregations

CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)168 Test (org.junit.Test)121 EntityManager (javax.persistence.EntityManager)79 TestForIssue (org.hibernate.testing.TestForIssue)38 AbstractMetamodelSpecificTest (org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)30 Customer (org.hibernate.jpa.test.metamodel.Customer)21 Predicate (javax.persistence.criteria.Predicate)15 Tuple (javax.persistence.Tuple)13 Person (org.hibernate.userguide.model.Person)12 List (java.util.List)11 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)11 ArrayList (java.util.ArrayList)10 Order (org.hibernate.jpa.test.metamodel.Order)10 ExecutionException (java.util.concurrent.ExecutionException)9 Message (org.apache.aries.tx.control.itests.entity.Message)6 TypedQuery (javax.persistence.TypedQuery)5 Root (javax.persistence.criteria.Root)4 Query (javax.persistence.Query)3 SkipForDialect (org.hibernate.testing.SkipForDialect)3 HashSet (java.util.HashSet)2