Search in sources :

Example 21 with ForeignKeyDescriptor

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

the class EntityWithOneToOneSharingPrimaryKeyTest method basicTest.

@Test
public void basicTest(SessionFactoryScope scope) {
    final EntityPersister entityDescriptor = scope.getSessionFactory().getMappingMetamodel().findEntityDescriptor(EntityWithOneToOneSharingPrimaryKey.class);
    final ModelPart otherAssociation = entityDescriptor.findSubPart("other");
    assertThat(otherAssociation, instanceOf(ToOneAttributeMapping.class));
    final ToOneAttributeMapping otherAttributeMapping = (ToOneAttributeMapping) otherAssociation;
    ForeignKeyDescriptor foreignKeyDescriptor = otherAttributeMapping.getForeignKeyDescriptor();
    foreignKeyDescriptor.visitKeySelectables((columnIndex, selection) -> {
        assertThat(selection.getContainingTableExpression(), is("entity_o2o_sharepk"));
        assertThat(selection.getSelectionExpression(), is("id"));
    });
    foreignKeyDescriptor.visitTargetSelectables((columnIndex, selection) -> {
        assertThat(selection.getContainingTableExpression(), is("SIMPLE_ENTITY"));
        assertThat(selection.getSelectionExpression(), is("id"));
    });
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) ModelPart(org.hibernate.metamodel.mapping.ModelPart) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

ForeignKeyDescriptor (org.hibernate.metamodel.mapping.ForeignKeyDescriptor)21 ModelPart (org.hibernate.metamodel.mapping.ModelPart)12 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)10 EntityPersister (org.hibernate.persister.entity.EntityPersister)9 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)7 NavigablePath (org.hibernate.query.spi.NavigablePath)7 QuerySpec (org.hibernate.sql.ast.tree.select.QuerySpec)7 AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)6 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)5 Expression (org.hibernate.sql.ast.tree.expression.Expression)5 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)5 SqlSelectionImpl (org.hibernate.sql.results.internal.SqlSelectionImpl)5 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 BasicValuedModelPart (org.hibernate.metamodel.mapping.BasicValuedModelPart)4 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)4 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)4 Test (org.junit.jupiter.api.Test)4 AbstractMap (java.util.AbstractMap)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3