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