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