use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.
the class DynamicCompositeIdBasicBindingTests method testBinding.
@Test
public void testBinding(ServiceRegistryScope scope) {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources(scope.getRegistry()).addResource("org/hibernate/orm/test/bootstrap/binding/hbm/cid/nonaggregated/dynamic/DynamicCompositeIdBasic.hbm.xml").buildMetadata().buildSessionFactory();
try {
final EntityPersister entityDescriptor = sessionFactory.getRuntimeMetamodels().getMappingMetamodel().findEntityDescriptor("DynamicCompositeIdBasic");
assertThat(entityDescriptor.getNumberOfAttributeMappings(), is(1));
final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
assertThat(identifierMapping, instanceOf(EmbeddedIdentifierMappingImpl.class));
final EmbeddedIdentifierMappingImpl cid = (EmbeddedIdentifierMappingImpl) identifierMapping;
assertThat(cid.getEmbeddableTypeDescriptor().getNumberOfAttributeMappings(), is(2));
final AttributeMapping key1 = cid.getEmbeddableTypeDescriptor().findAttributeMapping("key1");
assertThat(key1, notNullValue());
final AttributeMapping key2 = cid.getEmbeddableTypeDescriptor().findAttributeMapping("key2");
assertThat(key2, notNullValue());
final AttributeMapping attr1 = entityDescriptor.findAttributeMapping("attr1");
assertThat(attr1, notNullValue());
} finally {
sessionFactory.close();
}
}
use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.
the class SimpleHbmTests method testBinding.
@Test
public void testBinding(ServiceRegistryScope scope) {
final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) new MetadataSources(scope.getRegistry()).addResource("org/hibernate/orm/test/bootstrap/binding/hbm/simple/pojo/SimpleEntity.hbm.xml").buildMetadata().buildSessionFactory();
final EntityPersister entityDescriptor = sessionFactory.getRuntimeMetamodels().getMappingMetamodel().findEntityDescriptor(SimpleEntity.class);
final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
assertThat(identifierMapping, instanceOf(BasicEntityIdentifierMapping.class));
final BasicEntityIdentifierMapping bid = (BasicEntityIdentifierMapping) identifierMapping;
assertThat(bid.getFetchableName(), is("id"));
assertThat(bid.getPartName(), is(EntityIdentifierMapping.ROLE_LOCAL_NAME));
assertThat(entityDescriptor.getNumberOfAttributeMappings(), is(1));
assertThat(entityDescriptor.getNumberOfDeclaredAttributeMappings(), is(1));
final AttributeMapping nameAttr = entityDescriptor.findAttributeMapping("name");
assertThat(nameAttr, notNullValue());
}
use of org.hibernate.metamodel.mapping.AttributeMapping in project hibernate-orm by hibernate.
the class CriteriaEntityGraphTest 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 EntityGraphLoadPlanBuilderTest 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 DirtyCheckingTest method checkConverterMutabilityPlans.
@Test
public void checkConverterMutabilityPlans() {
final EntityPersister persister = sessionFactory().getMappingMetamodel().getEntityDescriptor(SomeEntity.class.getName());
final AttributeMapping numberMapping = persister.findAttributeMapping("number");
final AttributeMapping nameMapping = persister.findAttributeMapping("name");
assertFalse(persister.getPropertyType("number").isMutable());
assertTrue(persister.getPropertyType("name").isMutable());
}
Aggregations