Search in sources :

Example 6 with EmbeddedAttributeMapping

use of org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping 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 7 with EmbeddedAttributeMapping

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

the class InstantiationTests method runtimeModelTest.

@Test
public void runtimeModelTest(SessionFactoryScope scope) {
    final RuntimeMetamodels runtimeMetamodels = scope.getSessionFactory().getRuntimeMetamodels();
    final MappingMetamodel mappingMetamodel = runtimeMetamodels.getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(Person.class);
    final EmbeddedAttributeMapping nameEmbedded = (EmbeddedAttributeMapping) entityDescriptor.findAttributeMapping("name");
    final EmbeddableMappingType nameEmbeddable = nameEmbedded.getEmbeddableTypeDescriptor();
    final EmbeddableRepresentationStrategy nameRepStrategy = nameEmbeddable.getRepresentationStrategy();
    assertThat(nameRepStrategy.getMode()).isEqualTo(RepresentationMode.POJO);
    assertThat(nameRepStrategy.getInstantiator()).isInstanceOf(NameInstantiator.class);
    nameEmbeddable.forEachAttributeMapping((position, attribute) -> {
        assertThat(attribute.getPropertyAccess().getSetter()).isNull();
    });
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) EmbeddableRepresentationStrategy(org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy) EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) RuntimeMetamodels(org.hibernate.metamodel.RuntimeMetamodels) EmbeddableMappingType(org.hibernate.metamodel.mapping.EmbeddableMappingType) Test(org.junit.jupiter.api.Test)

Example 8 with EmbeddedAttributeMapping

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

the class InstantiationTests method runtimeModelTest.

@Test
public void runtimeModelTest(SessionFactoryScope scope) {
    final RuntimeMetamodels runtimeMetamodels = scope.getSessionFactory().getRuntimeMetamodels();
    final MappingMetamodel mappingMetamodel = runtimeMetamodels.getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(Person.class);
    final EmbeddedAttributeMapping nameEmbedded = (EmbeddedAttributeMapping) entityDescriptor.findAttributeMapping("name");
    final EmbeddableMappingType nameEmbeddable = nameEmbedded.getEmbeddableTypeDescriptor();
    final EmbeddableRepresentationStrategy nameRepStrategy = nameEmbeddable.getRepresentationStrategy();
    assertThat(nameRepStrategy.getMode()).isEqualTo(RepresentationMode.POJO);
    assertThat(nameRepStrategy.getInstantiator()).isInstanceOf(NameInstantiator.class);
    nameEmbeddable.forEachAttributeMapping((position, attribute) -> {
        assertThat(attribute.getPropertyAccess().getSetter()).isNull();
    });
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) EmbeddableRepresentationStrategy(org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy) EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) RuntimeMetamodels(org.hibernate.metamodel.RuntimeMetamodels) EmbeddableMappingType(org.hibernate.metamodel.mapping.EmbeddableMappingType) Test(org.junit.jupiter.api.Test)

Aggregations

EmbeddedAttributeMapping (org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping)8 AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)4 EmbeddableMappingType (org.hibernate.metamodel.mapping.EmbeddableMappingType)4 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 RuntimeMetamodels (org.hibernate.metamodel.RuntimeMetamodels)3 EntityPersister (org.hibernate.persister.entity.EntityPersister)3 List (java.util.List)2 FetchTiming (org.hibernate.engine.FetchTiming)2 MappingMetamodel (org.hibernate.metamodel.MappingMetamodel)2 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)2 ModelPart (org.hibernate.metamodel.mapping.ModelPart)2 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)2 EmbeddableRepresentationStrategy (org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy)2 AbstractMap (java.util.AbstractMap)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Objects (java.util.Objects)1