use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class MultiSelectTests method simpleArrayTest.
@Test
public void simpleArrayTest(SessionFactoryScope scope) {
scope.inTransaction((session) -> {
final CriteriaBuilder nodeBuilder = session.getFactory().getNodeBuilder();
final CriteriaQuery criteria = nodeBuilder.createQuery();
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
final EntityType<BasicEntity> model = root.getModel();
criteria.select(nodeBuilder.array(root.get(model.getDeclaredSingularAttribute("id", Integer.class)), root.get(model.getDeclaredSingularAttribute("data", String.class))));
final List<Object[]> results = session.createQuery(criteria).list();
assertThat(results).hasSize(1);
final Object[] firstResult = results.get(0);
assertThat(firstResult[0]).isEqualTo(1);
assertThat(firstResult[1]).isEqualTo("abc");
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class MultiSelectTests method singleSelectionTupleTest.
@Test
public void singleSelectionTupleTest(SessionFactoryScope scope) {
scope.inTransaction((session) -> {
final CriteriaBuilder nodeBuilder = session.getFactory().getNodeBuilder();
final CriteriaQuery criteria = nodeBuilder.createTupleQuery();
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
final EntityType<BasicEntity> model = root.getModel();
criteria.select(root.get(model.getDeclaredSingularAttribute("id", Integer.class)));
final List<Tuple> results = session.createQuery(criteria).list();
assertThat(results).hasSize(1);
final Tuple firstResult = results.get(0);
assertThat(firstResult.get(0)).isEqualTo(1);
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class SubQueryTests method modifiedSubQueryHqlTest.
@Test
public void modifiedSubQueryHqlTest(SessionFactoryScope scope) {
scope.inTransaction((session) -> {
session.persist(new BasicEntity(2368, "irrelevant"));
session.persist(new BasicEntity(2578, "irrelevant"));
session.persist(new BasicEntity(3000, "irrelevant"));
session.persist(new BasicEntity(10000, "irrelevant"));
session.persist(new BasicEntity(10050, "irrelevant"));
});
scope.inTransaction((session) -> {
final String qry = "select e.id from BasicEntity e where e.id > all (select s.id from BasicEntity s where s.id > 1)";
session.createQuery(qry).list();
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class BasicCriteriaExecutionTests method testExecutingBasicCriteriaQueryLiteralPredicate.
@Test
public void testExecutingBasicCriteriaQueryLiteralPredicate(SessionFactoryScope scope) {
scope.inTransaction(session -> {
final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
final CriteriaQuery<Object> criteria = criteriaBuilder.createQuery();
final Root<BasicEntity> root = criteria.from(BasicEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(criteriaBuilder.literal(1), criteriaBuilder.literal(1)));
session.createQuery(criteria).list();
});
}
use of org.hibernate.testing.orm.domain.gambit.BasicEntity in project hibernate-orm by hibernate.
the class BasicCriteriaExecutionTests method testCriteriaEntityJoin.
@Test
public void testCriteriaEntityJoin(SessionFactoryScope scope) {
scope.inStatelessTransaction(session -> {
final HibernateCriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
final JpaCriteriaQuery<Object> criteria = criteriaBuilder.createQuery();
final JpaRoot<BasicEntity> root = criteria.from(BasicEntity.class);
root.join(BasicEntity.class, SqmJoinType.CROSS);
criteria.select(root);
session.createQuery(criteria).list();
});
}
Aggregations