Search in sources :

Example 11 with RuntimeMetamodels

use of org.hibernate.metamodel.RuntimeMetamodels in project hibernate-orm by hibernate.

the class EmbeddableDefaultAccessTests method verifyRuntimeModel.

@Test
public void verifyRuntimeModel(SessionFactoryScope scope) {
    final RuntimeMetamodels runtimeMetamodels = scope.getSessionFactory().getRuntimeMetamodels();
    final EntityMappingType personDescriptor = runtimeMetamodels.getEntityMappingType(Person2.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("first");
    assertThat(nameLast.getAttributeName()).isEqualTo("last");
    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("first");
    assertThat(aliasLast.getAttributeName()).isEqualTo("last");
}
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 12 with RuntimeMetamodels

use of org.hibernate.metamodel.RuntimeMetamodels in project hibernate-orm by hibernate.

the class AttributeOrderingTests method testOrdering.

@Test
public void testOrdering(DomainModelScope modelScope, SessionFactoryScope sfScope) {
    // Force the creation of the session factory
    // We need this because properties are only sorted when finishing the initialization of the domain model
    SessionFactoryImplementor sessionFactory = sfScope.getSessionFactory();
    // check the boot model.. it should have been sorted as part of calls to
    // prepare for mapping model creation
    verifyBootModel(modelScope);
    // Also check the mapping model *and* the persister model - these need to be in-sync as far as ordering
    final RuntimeMetamodels runtimeMetamodels = sessionFactory.getRuntimeMetamodels();
    verifyRuntimeEntityMapping(runtimeMetamodels.getEntityMappingType(TheEntity.class));
    verifyRuntimeEntityMapping(runtimeMetamodels.getEntityMappingType("TheEntityHbm"));
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) RuntimeMetamodels(org.hibernate.metamodel.RuntimeMetamodels) Test(org.junit.jupiter.api.Test)

Example 13 with RuntimeMetamodels

use of org.hibernate.metamodel.RuntimeMetamodels 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 14 with RuntimeMetamodels

use of org.hibernate.metamodel.RuntimeMetamodels 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

RuntimeMetamodels (org.hibernate.metamodel.RuntimeMetamodels)14 Test (org.junit.jupiter.api.Test)9 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)7 EntityPersister (org.hibernate.persister.entity.EntityPersister)7 EmbeddableMappingType (org.hibernate.metamodel.mapping.EmbeddableMappingType)4 EmbeddedAttributeMapping (org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping)4 AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)3 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)3 SingularAttributeMapping (org.hibernate.metamodel.mapping.SingularAttributeMapping)3 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 MappingMetamodel (org.hibernate.metamodel.MappingMetamodel)2 AttributeMetadata (org.hibernate.metamodel.mapping.AttributeMetadata)2 NaturalIdMapping (org.hibernate.metamodel.mapping.NaturalIdMapping)2 EmbeddedCollectionPart (org.hibernate.metamodel.mapping.internal.EmbeddedCollectionPart)2 EmbeddableRepresentationStrategy (org.hibernate.metamodel.spi.EmbeddableRepresentationStrategy)2 TestForIssue (org.hibernate.testing.TestForIssue)2 EntityMetamodel (org.hibernate.tuple.entity.EntityMetamodel)2 NotYetImplementedFor6Exception (org.hibernate.NotYetImplementedFor6Exception)1 RootGraphImpl (org.hibernate.graph.internal.RootGraphImpl)1 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)1