use of org.hibernate.metamodel.mapping.SingularAttributeMapping in project hibernate-orm by hibernate.
the class InheritedNaturalIdTest method verifyMappingModel.
@Test
@TestForIssue(jiraKey = "HHH-10360")
public void verifyMappingModel(SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final EntityMappingType userMapping = sessionFactory.getRuntimeMetamodels().getEntityMappingType(User.class);
final SingularAttributeMapping uidMapping = ((SimpleNaturalIdMapping) userMapping.getNaturalIdMapping()).getAttribute();
assertThat(uidMapping.getAttributeName(), is("uid"));
final StateArrayContributorMetadata uidMetadata = uidMapping.getAttributeMetadataAccess().resolveAttributeMetadata(null);
assertThat(uidMetadata.isNullable(), is(true));
final EntityPersister rootEntityPersister = userMapping.getEntityPersister();
final int uidLegacyPropertyIndex = rootEntityPersister.getEntityMetamodel().getPropertyIndex("uid");
assertThat(uidLegacyPropertyIndex, is(0));
assertThat(rootEntityPersister.getPropertyNullability()[uidLegacyPropertyIndex], is(true));
}
use of org.hibernate.metamodel.mapping.SingularAttributeMapping in project hibernate-orm by hibernate.
the class ImmutableEntityNaturalIdTest method testNaturalIdMapping.
@Test
public void testNaturalIdMapping(SessionFactoryScope scope) {
final EntityMappingType buildingMapping = scope.getSessionFactory().getRuntimeMetamodels().getEntityMappingType(Building.class);
final NaturalIdMapping naturalIdMapping = buildingMapping.getNaturalIdMapping();
assertThat(naturalIdMapping, notNullValue());
assertThat(naturalIdMapping.getNaturalIdAttributes().size(), is(3));
// nullability is not specified, so they should be nullable by annotations-specific default
for (SingularAttributeMapping attribute : naturalIdMapping.getNaturalIdAttributes()) {
assertThat(attribute.getAttributeMetadataAccess().resolveAttributeMetadata(null).isNullable(), is(true));
}
final EntityPersister entityPersister = buildingMapping.getEntityPersister();
assertThat("Class should have a natural key", entityPersister.hasNaturalIdentifier(), is(true));
final EntityMetamodel entityMetamodel = entityPersister.getEntityMetamodel();
assertThat("Wrong number of attributes", entityMetamodel.getNaturalIdentifierProperties().length, is(3));
// nullability is not specified, so they should be nullable by annotations-specific default
assertTrue(entityPersister.getPropertyNullability()[entityMetamodel.getPropertyIndex("address")]);
assertTrue(entityPersister.getPropertyNullability()[entityMetamodel.getPropertyIndex("city")]);
assertTrue(entityPersister.getPropertyNullability()[entityMetamodel.getPropertyIndex("state")]);
}
Aggregations