Search in sources :

Example 1 with Bindable

use of javax.persistence.metamodel.Bindable in project hibernate-orm by hibernate.

the class AbstractManagedType method getBuilder.

public Builder<X> getBuilder() {
    if (locked) {
        throw new IllegalStateException("Type has been locked");
    }
    return new Builder<X>() {

        @Override
        @SuppressWarnings("unchecked")
        public void addAttribute(Attribute<X, ?> attribute) {
            declaredAttributes.put(attribute.getName(), attribute);
            final Bindable.BindableType bindableType = ((Bindable) attribute).getBindableType();
            switch(bindableType) {
                case SINGULAR_ATTRIBUTE:
                    {
                        declaredSingularAttributes.put(attribute.getName(), (SingularAttribute<X, ?>) attribute);
                        break;
                    }
                case PLURAL_ATTRIBUTE:
                    {
                        declaredPluralAttributes.put(attribute.getName(), (PluralAttribute<X, ?, ?>) attribute);
                        break;
                    }
                default:
                    {
                        throw new AssertionFailure("unknown bindable type: " + bindableType);
                    }
            }
        }
    };
}
Also used : SingularAttribute(javax.persistence.metamodel.SingularAttribute) AssertionFailure(org.hibernate.annotations.common.AssertionFailure) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) SetAttribute(javax.persistence.metamodel.SetAttribute) CollectionAttribute(javax.persistence.metamodel.CollectionAttribute) MapAttribute(javax.persistence.metamodel.MapAttribute) ListAttribute(javax.persistence.metamodel.ListAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) Bindable(javax.persistence.metamodel.Bindable)

Example 2 with Bindable

use of javax.persistence.metamodel.Bindable 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

Bindable (javax.persistence.metamodel.Bindable)2 SingularAttribute (javax.persistence.metamodel.SingularAttribute)2 JoinType (javax.persistence.criteria.JoinType)1 Attribute (javax.persistence.metamodel.Attribute)1 CollectionAttribute (javax.persistence.metamodel.CollectionAttribute)1 ListAttribute (javax.persistence.metamodel.ListAttribute)1 MapAttribute (javax.persistence.metamodel.MapAttribute)1 PluralAttribute (javax.persistence.metamodel.PluralAttribute)1 SetAttribute (javax.persistence.metamodel.SetAttribute)1 Type (javax.persistence.metamodel.Type)1 AssertionFailure (org.hibernate.annotations.common.AssertionFailure)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