Search in sources :

Example 51 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class EntityPersister method breakDownJdbcValues.

@Override
default void breakDownJdbcValues(Object domainValue, JdbcValueConsumer valueConsumer, SharedSessionContractImplementor session) {
    final List<AttributeMapping> attributeMappings = getAttributeMappings();
    if (domainValue instanceof Object[]) {
        final Object[] values = (Object[]) domainValue;
        for (int i = 0; i < attributeMappings.size(); i++) {
            final AttributeMapping attributeMapping = attributeMappings.get(i);
            attributeMapping.breakDownJdbcValues(values[i], valueConsumer, session);
        }
    } else {
        for (int i = 0; i < attributeMappings.size(); i++) {
            final AttributeMapping attributeMapping = attributeMappings.get(i);
            final Object attributeValue = attributeMapping.getPropertyAccess().getGetter().get(domainValue);
            attributeMapping.breakDownJdbcValues(attributeValue, valueConsumer, session);
        }
    }
}
Also used : AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping)

Example 52 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class HqlEntityGraphTest method getFetchable.

private Fetchable getFetchable(String attributeName, Class entityClass) {
    EntityPersister person = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().findEntityDescriptor(entityClass.getName());
    Collection<AttributeMapping> attributeMappings = person.getAttributeMappings();
    Fetchable fetchable = null;
    for (AttributeMapping mapping : attributeMappings) {
        if (mapping.getAttributeName().equals(attributeName)) {
            fetchable = (Fetchable) mapping;
        }
    }
    return fetchable;
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Fetchable(org.hibernate.sql.results.graph.Fetchable) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping)

Example 53 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class EmbeddableAccessTests method verifyRuntimeModel.

@Test
public void verifyRuntimeModel(SessionFactoryScope scope) {
    final RuntimeMetamodels runtimeMetamodels = scope.getSessionFactory().getRuntimeMetamodels();
    final EntityMappingType personDescriptor = runtimeMetamodels.getEntityMappingType(Person.class);
    // Person defines FIELD access, while Name uses PROPERTY
    // - if we find the property annotations, the attribute names will be
    // `firstName` and `lastName`, and the columns `first_name` and `last_name`
    // - otherwise, we have property and column names being `first` and `last`
    final EmbeddableMappingType nameEmbeddable = ((EmbeddedAttributeMapping) personDescriptor.findAttributeMapping("name")).getEmbeddableTypeDescriptor();
    assertThat(nameEmbeddable.getNumberOfAttributeMappings()).isEqualTo(2);
    final AttributeMapping nameFirst = nameEmbeddable.getAttributeMapping(0);
    final AttributeMapping nameLast = nameEmbeddable.getAttributeMapping(1);
    assertThat(nameFirst.getAttributeName()).isEqualTo("firstName");
    assertThat(nameLast.getAttributeName()).isEqualTo("lastName");
    final PluralAttributeMapping aliasesAttribute = (PluralAttributeMapping) personDescriptor.findAttributeMapping("aliases");
    final EmbeddableMappingType aliasEmbeddable = ((EmbeddedCollectionPart) aliasesAttribute.getElementDescriptor()).getEmbeddableTypeDescriptor();
    assertThat(aliasEmbeddable.getNumberOfAttributeMappings()).isEqualTo(2);
    final AttributeMapping aliasFirst = nameEmbeddable.getAttributeMapping(0);
    final AttributeMapping aliasLast = nameEmbeddable.getAttributeMapping(1);
    assertThat(aliasFirst.getAttributeName()).isEqualTo("firstName");
    assertThat(aliasLast.getAttributeName()).isEqualTo("lastName");
}
Also used : EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) EmbeddedCollectionPart(org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) RuntimeMetamodels(org.hibernate.metamodel.RuntimeMetamodels) EmbeddableMappingType(org.hibernate.metamodel.mapping.EmbeddableMappingType) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) Test(org.junit.jupiter.api.Test)

Example 54 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class PluralAttributeMappingTests method testArrays.

@Test
public void testArrays(SessionFactoryScope scope) {
    final MappingMetamodel domainModel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor(EntityOfArrays.class);
    assertThat(containerEntityDescriptor.getNumberOfAttributeMappings(), is(2));
    final AttributeMapping arrayOfBasics = containerEntityDescriptor.findAttributeMapping("arrayOfBasics");
    assertThat(arrayOfBasics, notNullValue());
}
Also used : MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) Test(org.junit.jupiter.api.Test)

Example 55 with AttributeMapping

use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.

the class PluralAttributeMappingTests method testSets.

@Test
public void testSets(SessionFactoryScope scope) {
    final MappingMetamodel domainModel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor(EntityOfSets.class);
    assertThat(containerEntityDescriptor.getNumberOfAttributeMappings(), is(12));
    final AttributeMapping setOfBasics = containerEntityDescriptor.findAttributeMapping("setOfBasics");
    assertThat(setOfBasics, notNullValue());
    final AttributeMapping sortedSetOfBasics = containerEntityDescriptor.findAttributeMapping("sortedSetOfBasics");
    assertThat(sortedSetOfBasics, notNullValue());
    final AttributeMapping sortedSetOfBasicsWithSortNaturalByDefault = containerEntityDescriptor.findAttributeMapping("sortedSetOfBasicsWithSortNaturalByDefault");
    assertThat(sortedSetOfBasicsWithSortNaturalByDefault, notNullValue());
    final AttributeMapping orderedSetOfBasics = containerEntityDescriptor.findAttributeMapping("orderedSetOfBasics");
    assertThat(orderedSetOfBasics, notNullValue());
    final AttributeMapping setOfEnums = containerEntityDescriptor.findAttributeMapping("setOfEnums");
    assertThat(setOfEnums, notNullValue());
    final AttributeMapping setOfConvertedBasics = containerEntityDescriptor.findAttributeMapping("setOfConvertedEnums");
    assertThat(setOfConvertedBasics, notNullValue());
    final AttributeMapping setOfComponents = containerEntityDescriptor.findAttributeMapping("setOfComponents");
    assertThat(setOfComponents, notNullValue());
    final AttributeMapping extraLazySetOfComponents = containerEntityDescriptor.findAttributeMapping("extraLazySetOfComponents");
    assertThat(extraLazySetOfComponents, notNullValue());
    final AttributeMapping setOfOneToMany = containerEntityDescriptor.findAttributeMapping("setOfOneToMany");
    assertThat(setOfOneToMany, notNullValue());
    final AttributeMapping setOfManyToMany = containerEntityDescriptor.findAttributeMapping("setOfManyToMany");
    assertThat(setOfManyToMany, notNullValue());
}
Also used : MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)56 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)38 SingularAttributeMapping (org.hibernate.metamodel.mapping.SingularAttributeMapping)20 EmbeddedAttributeMapping (org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping)19 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)19 EntityPersister (org.hibernate.persister.entity.EntityPersister)17 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)13 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)12 DiscriminatedAssociationAttributeMapping (org.hibernate.metamodel.mapping.internal.DiscriminatedAssociationAttributeMapping)12 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)10 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)8 EmbeddableMappingType (org.hibernate.metamodel.mapping.EmbeddableMappingType)8 ModelPart (org.hibernate.metamodel.mapping.ModelPart)7 Expression (org.hibernate.sql.ast.tree.expression.Expression)7 ForeignKeyDescriptor (org.hibernate.metamodel.mapping.ForeignKeyDescriptor)6 NonAggregatedIdentifierMapping (org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping)6 Fetchable (org.hibernate.sql.results.graph.Fetchable)6 CascadeStyle (org.hibernate.engine.spi.CascadeStyle)5 NavigablePath (org.hibernate.query.spi.NavigablePath)5