Search in sources :

Example 1 with EmbeddedIdentifierMappingImpl

use of org.hibernate.metamodel.mapping.internal.EmbeddedIdentifierMappingImpl 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 EmbeddedIdentifierMappingImpl

use of org.hibernate.metamodel.mapping.internal.EmbeddedIdentifierMappingImpl in project hibernate-orm by hibernate.

the class DynamicCompositeIdManyToOneBindingTests 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/DynamicCompositeIdManyToOne.hbm.xml").buildMetadata().buildSessionFactory();
    try {
        final EntityPersister entityDescriptor = sessionFactory.getRuntimeMetamodels().getMappingMetamodel().findEntityDescriptor("DynamicCompositeIdManyToOne");
        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());
        assertThat(key1, instanceOf(BasicAttributeMapping.class));
        final AttributeMapping key2 = cid.getEmbeddableTypeDescriptor().findAttributeMapping("key2");
        assertThat(key2, notNullValue());
        assertThat(key2, instanceOf(ToOneAttributeMapping.class));
        final AttributeMapping attr1 = entityDescriptor.findAttributeMapping("attr1");
        assertThat(attr1, notNullValue());
        assertThat(attr1, instanceOf(BasicAttributeMapping.class));
    } finally {
        sessionFactory.close();
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) MetadataSources(org.hibernate.boot.MetadataSources) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) EmbeddedIdentifierMappingImpl(org.hibernate.metamodel.mapping.internal.EmbeddedIdentifierMappingImpl) Test(org.junit.jupiter.api.Test)

Aggregations

MetadataSources (org.hibernate.boot.MetadataSources)2 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)2 AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)2 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)2 EmbeddedIdentifierMappingImpl (org.hibernate.metamodel.mapping.internal.EmbeddedIdentifierMappingImpl)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 Test (org.junit.jupiter.api.Test)2 BasicAttributeMapping (org.hibernate.metamodel.mapping.internal.BasicAttributeMapping)1 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)1