Search in sources :

Example 1 with JoinType

use of javax.persistence.criteria.JoinType in project stdlib by petergeneric.

the class JPAJoin method join.

public JPAJoin join(final String relation) {
    final QRelation rel = entity.getRelation(relation);
    final JoinType joinType;
    // For non-nullable non-collection joins, use an INNER join instead of a LEFT join
    if (!rel.isNullable() && !rel.isCollection())
        joinType = JoinType.INNER;
    else
        joinType = JoinType.LEFT;
    final Join<Object, Object> join = root.join(relation, joinType);
    return new JPAJoin(builder, rel, join, rel.isCollection());
}
Also used : QRelation(com.peterphi.std.guice.hibernate.webquery.impl.QRelation) JoinType(javax.persistence.criteria.JoinType)

Example 2 with JoinType

use of javax.persistence.criteria.JoinType in project crnk-framework by crnk-project.

the class JoinRegistry method getOrCreateJoin.

private F getOrCreateJoin(MetaAttributePath srcPath, MetaAttribute targetAttr) {
    MetaAttributePath path = srcPath.concat(targetAttr);
    F parent = joinMap.get(srcPath);
    F join = joinMap.get(path);
    if (join == null) {
        JoinType joinType = query.getJoinType(path);
        join = backend.doJoin(targetAttr, joinType, parent);
        joinMap.put(path, join);
    }
    return join;
}
Also used : JoinType(javax.persistence.criteria.JoinType) MetaAttributePath(io.crnk.meta.model.MetaAttributePath)

Example 3 with JoinType

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

the class SingularAttributeJoinTest method testEntityModeMapJoins.

/**
 * When building a join from a non-class based entity (EntityMode.MAP), make sure you get the Bindable from
 * the SingularAttribute as the join model. If you don't, you'll get the first non-classed based entity
 * you added to your configuration. Regression for HHH-9142.
 */
@Test
public void testEntityModeMapJoins() throws Exception {
    CriteriaBuilderImpl criteriaBuilder = mock(CriteriaBuilderImpl.class);
    PathSource pathSource = mock(PathSource.class);
    SingularAttribute joinAttribute = mock(SingularAttribute.class);
    when(joinAttribute.getPersistentAttributeType()).thenReturn(Attribute.PersistentAttributeType.MANY_TO_ONE);
    Type joinType = mock(Type.class, withSettings().extraInterfaces(Bindable.class));
    when(joinAttribute.getType()).thenReturn(joinType);
    SingularAttributeJoin join = new SingularAttributeJoin(criteriaBuilder, null, pathSource, joinAttribute, JoinType.LEFT);
    assertEquals(joinType, join.getModel());
}
Also used : SingularAttributeJoin(org.hibernate.query.criteria.internal.path.SingularAttributeJoin) SingularAttribute(javax.persistence.metamodel.SingularAttribute) CriteriaBuilderImpl(org.hibernate.query.criteria.internal.CriteriaBuilderImpl) Type(javax.persistence.metamodel.Type) JoinType(javax.persistence.criteria.JoinType) PathSource(org.hibernate.query.criteria.internal.PathSource) Bindable(javax.persistence.metamodel.Bindable) Test(org.junit.Test)

Aggregations

JoinType (javax.persistence.criteria.JoinType)3 QRelation (com.peterphi.std.guice.hibernate.webquery.impl.QRelation)1 MetaAttributePath (io.crnk.meta.model.MetaAttributePath)1 Bindable (javax.persistence.metamodel.Bindable)1 SingularAttribute (javax.persistence.metamodel.SingularAttribute)1 Type (javax.persistence.metamodel.Type)1 CriteriaBuilderImpl (org.hibernate.query.criteria.internal.CriteriaBuilderImpl)1 PathSource (org.hibernate.query.criteria.internal.PathSource)1 SingularAttributeJoin (org.hibernate.query.criteria.internal.path.SingularAttributeJoin)1 Test (org.junit.Test)1