use of jakarta.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();
});
}
use of jakarta.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<BatchNodeMetadata> query = cb.createQuery(BatchNodeMetadata.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();
});
}
use of jakarta.persistence.criteria.MapJoin in project hibernate-orm by hibernate.
the class MapJoinTestWithEmbeddable method testSelectingKeyOfMapJoin.
@Test
public void testSelectingKeyOfMapJoin(EntityManagerFactoryScope scope) {
scope.inTransaction(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();
});
}
use of jakarta.persistence.criteria.MapJoin in project hibernate-orm by hibernate.
the class AbstractQueryCacheResultTransformerTest method testMapKeyList.
@Test
public void testMapKeyList(SessionFactoryScope scope) throws Exception {
CriteriaExecutor criteriaExecutor = new CriteriaExecutor() {
@Override
protected ResultTransformer getResultTransformer() {
return null;
}
@Override
protected JpaCriteriaQuery getCriteria(Session s) {
CriteriaBuilder builder = s.getCriteriaBuilder();
JpaCriteriaQuery criteria = (JpaCriteriaQuery) builder.createQuery();
Root<Student> root = criteria.from(Student.class);
final MapJoin<Object, Object, Order> addresses = root.joinMap("addresses", JoinType.INNER);
criteria.select(addresses.key());
/*
s.createCriteria( Student.class, "s" )
.createAlias( "s.addresses", "a", Criteria.INNER_JOIN )
.setProjection( Projections.property( "s.addresses" ) );
*/
return criteria;
}
};
HqlExecutor hqlExecutor = new HqlExecutor() {
@Override
public Query getQuery(Session s) {
return s.createQuery("select key(s.addresses) from Student s");
}
};
ResultChecker checker = results -> {
List resultList = (List) results;
assertEquals(2, resultList.size());
assertTrue(resultList.contains("home"));
assertTrue(resultList.contains("work"));
};
runTest(hqlExecutor, criteriaExecutor, checker, false, scope);
}
use of jakarta.persistence.criteria.MapJoin in project eclipselink by eclipse-ee4j.
the class CriteriaBuilderImpl method treat.
@Override
public <X, K, T, V extends T> MapJoin<X, K, V> treat(MapJoin<X, K, T> join, Class<V> type) {
MapJoinImpl parentJoin = (MapJoinImpl) join;
MapJoin joinImpl = null;
if (join instanceof BasicMapJoinImpl) {
joinImpl = new BasicMapJoinImpl<X, K, V>(parentJoin, this.metamodel, type, parentJoin.currentNode.treat(type), parentJoin.getModel(), parentJoin.getJoinType());
} else {
joinImpl = new MapJoinImpl<X, K, V>((Path) join, this.metamodel.managedType(type), this.metamodel, type, parentJoin.currentNode.treat(type), parentJoin.getModel(), parentJoin.getJoinType());
}
parentJoin.joins.add(joinImpl);
((FromImpl) joinImpl).isJoin = parentJoin.isJoin;
parentJoin.isJoin = false;
return joinImpl;
}
Aggregations