use of org.hibernate.metamodel.MappingMetamodel 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());
}
use of org.hibernate.metamodel.MappingMetamodel 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.MappingMetamodel 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.MappingMetamodel in project hibernate-orm by hibernate.
the class CompoundNaturalIdTests method testProcessing.
@Test
public void testProcessing(DomainModelScope domainModelScope, SessionFactoryScope factoryScope) {
final PersistentClass accountBootMapping = domainModelScope.getDomainModel().getEntityBinding(Account.class.getName());
assertThat(accountBootMapping.hasNaturalId(), is(true));
final Property username = accountBootMapping.getProperty("username");
assertThat(username.isNaturalIdentifier(), is(true));
final Property system = accountBootMapping.getProperty("system");
assertThat(system.isNaturalIdentifier(), is(true));
final MappingMetamodel mappingMetamodel = factoryScope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
final EntityPersister accountMapping = mappingMetamodel.findEntityDescriptor(Account.class);
assertThat(accountMapping.hasNaturalIdentifier(), is(true));
final NaturalIdMapping naturalIdMapping = accountMapping.getNaturalIdMapping();
assertThat(naturalIdMapping, notNullValue());
final List<SingularAttributeMapping> attributes = naturalIdMapping.getNaturalIdAttributes();
assertThat(attributes.size(), is(2));
// alphabetical matching overall processing
final SingularAttributeMapping first = attributes.get(0);
assertThat(first, notNullValue());
assertThat(first.getAttributeName(), is("system"));
final SingularAttributeMapping second = attributes.get(1);
assertThat(second, notNullValue());
assertThat(second.getAttributeName(), is("username"));
}
use of org.hibernate.metamodel.MappingMetamodel in project hibernate-orm by hibernate.
the class MappedFetchTests method baseline.
@Test
public void baseline(SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final MappingMetamodel domainModel = sessionFactory.getRuntimeMetamodels().getMappingMetamodel();
final EntityPersister rootEntityDescriptor = domainModel.getEntityDescriptor(RootEntity.class);
final SelectStatement sqlAst = LoaderSelectBuilder.createSelect(rootEntityDescriptor, null, rootEntityDescriptor.getIdentifierMapping(), null, 1, LoadQueryInfluencers.NONE, LockOptions.NONE, jdbcParameter -> {
}, sessionFactory);
assertThat(sqlAst.getDomainResultDescriptors().size(), is(1));
final DomainResult domainResult = sqlAst.getDomainResultDescriptors().get(0);
assertThat(domainResult, instanceOf(EntityResult.class));
final EntityResult entityResult = (EntityResult) domainResult;
final List<Fetch> fetches = entityResult.getFetches();
// name + both lists
assertThat(fetches.size(), is(3));
// order is alphabetical...
final Fetch nameFetch = fetches.get(0);
assertThat(nameFetch.getFetchedMapping().getFetchableName(), is("name"));
assertThat(nameFetch, instanceOf(BasicFetch.class));
final Fetch nickNamesFetch = fetches.get(1);
assertThat(nickNamesFetch.getFetchedMapping().getFetchableName(), is("nickNames"));
assertThat(nickNamesFetch, instanceOf(EagerCollectionFetch.class));
final Fetch simpleEntitiesFetch = fetches.get(2);
assertThat(simpleEntitiesFetch.getFetchedMapping().getFetchableName(), is("simpleEntities"));
assertThat(simpleEntitiesFetch, instanceOf(DelayedCollectionFetch.class));
final QuerySpec querySpec = sqlAst.getQuerySpec();
final TableGroup tableGroup = querySpec.getFromClause().getRoots().get(0);
assertThat(tableGroup.getModelPart(), is(rootEntityDescriptor));
assertThat(tableGroup.getTableGroupJoins().size(), is(1));
final TableGroupJoin collectionJoin = tableGroup.getTableGroupJoins().iterator().next();
assertThat(collectionJoin.getJoinedGroup().getModelPart(), is(nickNamesFetch.getFetchedMapping()));
assertThat(collectionJoin.getPredicate(), notNullValue());
assertThat(collectionJoin.getPredicate(), instanceOf(ComparisonPredicate.class));
}
Aggregations