Search in sources :

Example 6 with Path

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

the class CompositeParameterTests method testDeTypedInPredicateCriteria.

@Test
public void testDeTypedInPredicateCriteria(SessionFactoryScope scope) {
    final HibernateCriteriaBuilder builder = scope.getSessionFactory().getCriteriaBuilder();
    final JpaMetamodel jpaMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getJpaMetamodel();
    final EntityDomainType entityDescriptor = jpaMetamodel.entity(SimpleEntity.class);
    final SingularAttribute attribute = entityDescriptor.getSingularAttribute("composite");
    scope.inTransaction((session) -> {
        final JpaCriteriaQuery criteria = builder.createQuery(SimpleEntity.class);
        final JpaRoot root = criteria.from(entityDescriptor);
        final Path attrPath = root.get(attribute);
        final JpaParameterExpression parameter = builder.parameter(SimpleComposite.class);
        criteria.where(builder.in(attrPath, parameter));
        final QueryImplementor query = session.createQuery(criteria);
        query.setParameter(parameter, new SimpleComposite());
        query.list();
    });
}
Also used : Path(jakarta.persistence.criteria.Path) SingularAttribute(jakarta.persistence.metamodel.SingularAttribute) JpaRoot(org.hibernate.query.criteria.JpaRoot) HibernateCriteriaBuilder(org.hibernate.query.criteria.HibernateCriteriaBuilder) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType) JpaMetamodel(org.hibernate.metamodel.model.domain.JpaMetamodel) JpaCriteriaQuery(org.hibernate.query.criteria.JpaCriteriaQuery) JpaParameterExpression(org.hibernate.query.criteria.JpaParameterExpression) QueryImplementor(org.hibernate.query.spi.QueryImplementor) Test(org.junit.jupiter.api.Test)

Example 7 with Path

use of jakarta.persistence.criteria.Path in project eclipselink by eclipse-ee4j.

the class CriteriaBuilderImpl method treat.

@Override
public <X, T, E extends T> SetJoin<X, E> treat(SetJoin<X, T> join, Class<E> type) {
    SetJoinImpl parentJoin = (SetJoinImpl) join;
    SetJoin joinImpl = null;
    if (join instanceof BasicSetJoinImpl) {
        joinImpl = new BasicSetJoinImpl<X, E>(parentJoin, this.metamodel, type, parentJoin.currentNode.treat(type), parentJoin.getModel(), parentJoin.getJoinType());
    } else {
        joinImpl = new SetJoinImpl<X, E>((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;
}
Also used : Path(jakarta.persistence.criteria.Path) SetJoin(jakarta.persistence.criteria.SetJoin)

Example 8 with Path

use of jakarta.persistence.criteria.Path in project eclipselink by eclipse-ee4j.

the class CriteriaBuilderImpl method treat.

@Override
public <X, T, E extends T> CollectionJoin<X, E> treat(CollectionJoin<X, T> join, Class<E> type) {
    CollectionJoinImpl parentJoin = (CollectionJoinImpl) join;
    CollectionJoin joinImpl = null;
    if (join instanceof BasicCollectionJoinImpl) {
        joinImpl = new BasicCollectionJoinImpl<X, E>(parentJoin, this.metamodel, type, parentJoin.currentNode.treat(type), parentJoin.getModel(), parentJoin.getJoinType());
    } else {
        joinImpl = new CollectionJoinImpl<X, E>((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;
}
Also used : Path(jakarta.persistence.criteria.Path) CollectionJoin(jakarta.persistence.criteria.CollectionJoin)

Aggregations

Path (jakarta.persistence.criteria.Path)8 Test (org.junit.jupiter.api.Test)4 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)3 ListJoin (jakarta.persistence.criteria.ListJoin)2 MapJoin (jakarta.persistence.criteria.MapJoin)2 JpaCriteriaQuery (org.hibernate.query.criteria.JpaCriteriaQuery)2 JpaRoot (org.hibernate.query.criteria.JpaRoot)2 EntityManager (jakarta.persistence.EntityManager)1 TypedQuery (jakarta.persistence.TypedQuery)1 CollectionJoin (jakarta.persistence.criteria.CollectionJoin)1 CriteriaQuery (jakarta.persistence.criteria.CriteriaQuery)1 From (jakarta.persistence.criteria.From)1 Join (jakarta.persistence.criteria.Join)1 JoinType (jakarta.persistence.criteria.JoinType)1 Order (jakarta.persistence.criteria.Order)1 Root (jakarta.persistence.criteria.Root)1 Selection (jakarta.persistence.criteria.Selection)1 SetJoin (jakarta.persistence.criteria.SetJoin)1 SingularAttribute (jakarta.persistence.metamodel.SingularAttribute)1 Constructor (java.lang.reflect.Constructor)1