Search in sources :

Example 1 with MapJoin

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

the class AbstractFromImpl method joinMap.

@Override
@SuppressWarnings({ "unchecked" })
public <X, K, V> MapJoin<X, K, V> joinMap(String attributeName, JoinType jt) {
    final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute(attributeName);
    if (!attribute.isCollection()) {
        throw new IllegalArgumentException("Requested attribute was not a map");
    }
    final PluralAttribute pluralAttribute = (PluralAttribute) attribute;
    if (!PluralAttribute.CollectionType.MAP.equals(pluralAttribute.getCollectionType())) {
        throw new IllegalArgumentException("Requested attribute was not a map");
    }
    return (MapJoin<X, K, V>) join((MapAttribute) attribute, jt);
}
Also used : MapAttribute(javax.persistence.metamodel.MapAttribute) CollectionAttribute(javax.persistence.metamodel.CollectionAttribute) MapAttribute(javax.persistence.metamodel.MapAttribute) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) SetAttribute(javax.persistence.metamodel.SetAttribute) ListAttribute(javax.persistence.metamodel.ListAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) MapJoin(javax.persistence.criteria.MapJoin)

Example 2 with MapJoin

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

the class MapJoinTestWithEmbeddable method testSelectingKeyOfMapJoin.

@Test
@TestForIssue(jiraKey = "HHH-10455")
public void testSelectingKeyOfMapJoin() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        CriteriaQuery<Node> query = cb.createQuery(Node.class);
        Root<Batch> root = query.from(Batch.class);
        MapJoin nodes = (MapJoin) root.join("batchNodeMetadata");
        query.select(nodes.key());
        query.where(cb.equal(root.get("id"), 1));
        entityManager.createQuery(query).getResultList();
    });
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) MapJoin(javax.persistence.criteria.MapJoin) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 3 with MapJoin

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

the class MapJoinTestWithEmbeddable method testSelectingValueOfMapJoin.

@Test
@TestForIssue(jiraKey = "HHH-10229")
public void testSelectingValueOfMapJoin() {
    doInJPA(this::entityManagerFactory, entityManager -> {
        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        CriteriaQuery<Node> query = cb.createQuery(Node.class);
        Root<Batch> root = query.from(Batch.class);
        MapJoin nodes = (MapJoin) root.join("batchNodeMetadata");
        query.select(nodes);
        query.where(cb.equal(root.get("id"), 1));
        entityManager.createQuery(query).getResultList();
    });
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) MapJoin(javax.persistence.criteria.MapJoin) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

MapJoin (javax.persistence.criteria.MapJoin)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 TestForIssue (org.hibernate.testing.TestForIssue)2 Test (org.junit.Test)2 Attribute (javax.persistence.metamodel.Attribute)1 CollectionAttribute (javax.persistence.metamodel.CollectionAttribute)1 ListAttribute (javax.persistence.metamodel.ListAttribute)1 MapAttribute (javax.persistence.metamodel.MapAttribute)1 PluralAttribute (javax.persistence.metamodel.PluralAttribute)1 SetAttribute (javax.persistence.metamodel.SetAttribute)1 SingularAttribute (javax.persistence.metamodel.SingularAttribute)1