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");
}
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"));
}
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();
});
}
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();
});
}
Aggregations