Search in sources :

Example 1 with Path

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

the class AbstractPathImplTest method testIllegalDereference.

@Test
public void testIllegalDereference() {
    EntityManager em = getOrCreateEntityManager();
    try {
        CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
        CriteriaQuery<Order> criteria = criteriaBuilder.createQuery(Order.class);
        Root<Order> orderRoot = criteria.from(Order.class);
        Path simplePath = orderRoot.get("totalPrice");
        // this should cause an ISE...
        try {
            simplePath.get("yabbadabbado");
            fail("Attempt to dereference basic path should throw IllegalStateException");
        } catch (IllegalStateException expected) {
        }
    } finally {
        em.close();
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(org.hibernate.jpa.test.metamodel.Order) Path(javax.persistence.criteria.Path) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test) AbstractMetamodelSpecificTest(org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)

Example 2 with Path

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

the class SingularAttributeJoinTest method testEntityModeMapJoinCriteriaQuery.

@Test
public void testEntityModeMapJoinCriteriaQuery() throws Exception {
    final EntityManager entityManager = entityManagerFactory().createEntityManager();
    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery criteriaQuery = criteriaBuilder.createQuery();
    javax.persistence.metamodel.EntityType distributionEntity = getEntityType("Distribution");
    From distributionFrom = criteriaQuery.from(distributionEntity);
    From policyJoin = distributionFrom.join("policy");
    Path policyId = policyJoin.get("policyId");
    criteriaQuery.select(policyId);
    TypedQuery typedQuery = entityManager.createQuery(criteriaQuery);
//        typedQuery.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Path(javax.persistence.criteria.Path) EntityManager(javax.persistence.EntityManager) TypedQuery(javax.persistence.TypedQuery) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) From(javax.persistence.criteria.From) Test(org.junit.Test)

Example 3 with Path

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

the class CriteriaUpdateImpl method set.

@Override
@SuppressWarnings("unchecked")
public CriteriaUpdate<T> set(String attributeName, Object value) {
    final Path attributePath = getRoot().get(attributeName);
    final Expression valueExpression = value == null ? criteriaBuilder().nullLiteral(attributePath.getJavaType()) : criteriaBuilder().literal(value);
    addAssignment(attributePath, valueExpression);
    return this;
}
Also used : SingularAttributePath(org.hibernate.query.criteria.internal.path.SingularAttributePath) Path(javax.persistence.criteria.Path) Expression(javax.persistence.criteria.Expression)

Aggregations

Path (javax.persistence.criteria.Path)3 EntityManager (javax.persistence.EntityManager)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Test (org.junit.Test)2 TypedQuery (javax.persistence.TypedQuery)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 Expression (javax.persistence.criteria.Expression)1 From (javax.persistence.criteria.From)1 AbstractMetamodelSpecificTest (org.hibernate.jpa.test.metamodel.AbstractMetamodelSpecificTest)1 Order (org.hibernate.jpa.test.metamodel.Order)1 SingularAttributePath (org.hibernate.query.criteria.internal.path.SingularAttributePath)1