use of org.javaee7.jpa.aggregate_function_in_select.entity.TestEntity in project javaee7-samples by javaee-samples.
the class QueryRepository method buildGetAll.
/**
* Builds a criteria query equal to the JPQL
*
* <code>SELECT _testEntity FROM TestEntity _testEntity</code>
*
*
*/
private TypedQuery<TestEntity> buildGetAll() {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<TestEntity> criteriaQuery = criteriaBuilder.createQuery(TestEntity.class);
Root<TestEntity> root = criteriaQuery.from(TestEntity.class);
criteriaQuery.select(root);
return entityManager.createQuery(criteriaQuery);
}
use of org.javaee7.jpa.aggregate_function_in_select.entity.TestEntity in project javaee7-samples by javaee-samples.
the class DynamicNamedQueryTest method testDynamicNamedCriteriaQueries.
@Test
public void testDynamicNamedCriteriaQueries() throws IOException, SAXException {
// Nothing inserted yet, data base should not contain any entities
// (this tests that a simple query without parameters works as named query created by Criteria)
assertTrue(testService.getAll().size() == 0);
// Insert one entity
TestEntity testEntity = new TestEntity();
testEntity.setValue("myValue");
testService.save(testEntity);
// The total amount of entities should be 1
assertTrue(testService.getAll().size() == 1);
// The entity with "myValue" should be found
// (this tests that a query with a parameter works as named query created by Criteria)
assertTrue(testService.getByValue("myValue").size() == 1);
}
Aggregations