use of jakarta.persistence.criteria.MapJoin in project hibernate-orm by hibernate.
the class MapJoinTestWithEmbeddable method testSelectingValueOfMapJoin.
@Test
public void testSelectingValueOfMapJoin(EntityManagerFactoryScope scope) {
scope.inTransaction(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 AbstractQueryCacheResultTransformerTest method testMapValueList.
@Test
public void testMapValueList(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.value());
/*
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 value(s.addresses) from Student s");
}
};
ResultChecker checker = results -> {
List resultList = (List) results;
assertEquals(2, resultList.size());
assertTrue(resultList.contains(yogiExpected.getAddresses().get("home")));
assertTrue(resultList.contains(yogiExpected.getAddresses().get("work")));
};
runTest(hqlExecutor, criteriaExecutor, checker, false, scope);
}
use of jakarta.persistence.criteria.MapJoin in project hibernate-orm by hibernate.
the class AbstractQueryCacheResultTransformerTest method testMapEntryList.
@Test
public void testMapEntryList(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.entry());
/*
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 entry(s.addresses) from Student s");
}
};
ResultChecker checker = results -> {
List resultList = (List) results;
assertEquals(2, resultList.size());
Iterator it = resultList.iterator();
assertTrue(resultList.get(0) instanceof Map.Entry);
Map.Entry entry = (Map.Entry) it.next();
if ("home".equals(entry.getKey())) {
assertEquals(yogiExpected.getAddresses().get("home"), entry.getValue());
entry = (Map.Entry) it.next();
assertEquals(yogiExpected.getAddresses().get("work"), entry.getValue());
} else {
assertEquals("work", entry.getKey());
assertEquals(yogiExpected.getAddresses().get("work"), entry.getValue());
entry = (Map.Entry) it.next();
assertEquals(yogiExpected.getAddresses().get("home"), entry.getValue());
}
};
runTest(hqlExecutor, criteriaExecutor, checker, false, scope);
}
Aggregations