use of org.hibernate.metamodel.mapping.EntityIdentifierMapping 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.EntityIdentifierMapping 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.EntityIdentifierMapping in project hibernate-orm by hibernate.
the class DiscriminatedAssociationAttributeMapping method disassemble.
@Override
public Object disassemble(Object value, SharedSessionContractImplementor session) {
if (value == null) {
return null;
}
final EntityMappingType concreteMappingType = determineConcreteType(value, session);
final EntityIdentifierMapping identifierMapping = concreteMappingType.getIdentifierMapping();
final Object discriminator = discriminatorMapping.getModelPart().resolveDiscriminatorForEntityType(concreteMappingType);
final Object identifier = identifierMapping.getIdentifier(value);
return new Object[] { discriminatorMapping.getDiscriminatorPart().disassemble(discriminator, session), identifierMapping.disassemble(identifier, session) };
}
use of org.hibernate.metamodel.mapping.EntityIdentifierMapping in project hibernate-orm by hibernate.
the class DiscriminatedAssociationAttributeMapping method breakDownJdbcValues.
@Override
public void breakDownJdbcValues(Object domainValue, JdbcValueConsumer valueConsumer, SharedSessionContractImplementor session) {
final EntityMappingType concreteMappingType = determineConcreteType(domainValue, session);
final Object discriminator = discriminatorMapping.getModelPart().resolveDiscriminatorForEntityType(concreteMappingType);
final Object disassembledDiscriminator = discriminatorMapping.getDiscriminatorPart().disassemble(discriminator, session);
valueConsumer.consume(disassembledDiscriminator, discriminatorMapping.getDiscriminatorPart());
final EntityIdentifierMapping identifierMapping = concreteMappingType.getIdentifierMapping();
final Object identifier = identifierMapping.getIdentifier(domainValue);
final Object disassembledKey = discriminatorMapping.getKeyPart().disassemble(identifier, session);
valueConsumer.consume(disassembledKey, discriminatorMapping.getKeyPart());
}
use of org.hibernate.metamodel.mapping.EntityIdentifierMapping in project hibernate-orm by hibernate.
the class DiscriminatedAssociationAttributeMapping method forEachDisassembledJdbcValue.
@Override
public int forEachDisassembledJdbcValue(Object value, Clause clause, int offset, JdbcValuesConsumer valuesConsumer, SharedSessionContractImplementor session) {
if (value != null) {
if (value.getClass().isArray()) {
final Object[] values = (Object[]) value;
valuesConsumer.consume(offset, values[0], discriminatorMapping.getDiscriminatorPart().getJdbcMapping());
valuesConsumer.consume(offset + 1, values[1], discriminatorMapping.getKeyPart().getJdbcMapping());
} else {
final EntityMappingType concreteMappingType = determineConcreteType(value, session);
final Object discriminator = discriminatorMapping.getModelPart().resolveDiscriminatorForEntityType(concreteMappingType);
final Object disassembledDiscriminator = discriminatorMapping.getDiscriminatorPart().disassemble(discriminator, session);
valuesConsumer.consume(offset, disassembledDiscriminator, discriminatorMapping.getDiscriminatorPart().getJdbcMapping());
final EntityIdentifierMapping identifierMapping = concreteMappingType.getIdentifierMapping();
final Object identifier = identifierMapping.getIdentifier(value);
final Object disassembledKey = discriminatorMapping.getKeyPart().disassemble(identifier, session);
valuesConsumer.consume(offset + 1, disassembledKey, discriminatorMapping.getKeyPart().getJdbcMapping());
}
}
return 2;
}
Aggregations