Search in sources :

Example 1 with AttributeMapping

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();
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) MetadataSources(org.hibernate.boot.MetadataSources) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) EmbeddedIdentifierMappingImpl(org.hibernate.metamodel.mapping.internal.EmbeddedIdentifierMappingImpl) Test(org.junit.jupiter.api.Test)

Example 2 with AttributeMapping

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());
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) MetadataSources(org.hibernate.boot.MetadataSources) BasicEntityIdentifierMapping(org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) BasicEntityIdentifierMapping(org.hibernate.metamodel.mapping.BasicEntityIdentifierMapping) Test(org.junit.jupiter.api.Test)

Example 3 with AttributeMapping

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;
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Fetchable(org.hibernate.sql.results.graph.Fetchable) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping)

Example 4 with AttributeMapping

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;
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Fetchable(org.hibernate.sql.results.graph.Fetchable) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) EmbeddedAttributeMapping(org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping)

Example 5 with AttributeMapping

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());
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) Test(org.junit.Test)

Aggregations

AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)56 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)38 SingularAttributeMapping (org.hibernate.metamodel.mapping.SingularAttributeMapping)20 EmbeddedAttributeMapping (org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping)19 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)19 EntityPersister (org.hibernate.persister.entity.EntityPersister)17 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)13 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)12 DiscriminatedAssociationAttributeMapping (org.hibernate.metamodel.mapping.internal.DiscriminatedAssociationAttributeMapping)12 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)10 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)8 EmbeddableMappingType (org.hibernate.metamodel.mapping.EmbeddableMappingType)8 ModelPart (org.hibernate.metamodel.mapping.ModelPart)7 Expression (org.hibernate.sql.ast.tree.expression.Expression)7 ForeignKeyDescriptor (org.hibernate.metamodel.mapping.ForeignKeyDescriptor)6 NonAggregatedIdentifierMapping (org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping)6 Fetchable (org.hibernate.sql.results.graph.Fetchable)6 CascadeStyle (org.hibernate.engine.spi.CascadeStyle)5 NavigablePath (org.hibernate.query.spi.NavigablePath)5