use of org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl in project hibernate-orm by hibernate.
the class AbstractEntityPersister method generateIdentifierMapping.
protected EntityIdentifierMapping generateIdentifierMapping(Supplier<?> templateInstanceCreator, PersistentClass bootEntityDescriptor, MappingModelCreationProcess creationProcess) {
final Type idType = getIdentifierType();
if (idType instanceof CompositeType) {
final CompositeType cidType = (CompositeType) idType;
// NOTE: the term `isEmbedded` here uses Hibernate's older (pre-JPA) naming for its "non-aggregated"
// composite-id support. It unfortunately conflicts with the JPA usage of "embedded". Here we normalize
// the legacy naming to the more descriptive encapsulated versus non-encapsulated phrasing
final boolean encapsulated = !cidType.isEmbedded();
if (encapsulated) {
// we have an `@EmbeddedId`
return MappingModelCreationHelper.buildEncapsulatedCompositeIdentifierMapping(this, bootEntityDescriptor.getIdentifierProperty(), bootEntityDescriptor.getIdentifierProperty().getName(), getTableName(), rootTableKeyColumnNames, cidType, creationProcess);
}
// otherwise we have a non-encapsulated composite-identifier
return generateNonEncapsulatedCompositeIdentifierMapping(creationProcess, bootEntityDescriptor);
}
final String columnDefinition;
final Long length;
final Integer precision;
final Integer scale;
if (bootEntityDescriptor.getIdentifier() == null) {
columnDefinition = null;
length = null;
precision = null;
scale = null;
} else {
Column column = bootEntityDescriptor.getIdentifier().getColumns().get(0);
columnDefinition = column.getSqlType();
length = column.getLength();
precision = column.getPrecision();
scale = column.getScale();
}
return new BasicEntityIdentifierMappingImpl(this, templateInstanceCreator, bootEntityDescriptor.getIdentifierProperty().getName(), getTableName(), rootTableKeyColumnNames[0], columnDefinition, length, precision, scale, (BasicType<?>) idType, creationProcess);
}
use of org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl in project hibernate-orm by hibernate.
the class JoinedSubclassEntityPersister method generateIdentifierMapping.
@Override
protected EntityIdentifierMapping generateIdentifierMapping(Supplier<?> templateInstanceCreator, PersistentClass bootEntityDescriptor, MappingModelCreationProcess creationProcess) {
final Type idType = getIdentifierType();
if (idType instanceof CompositeType) {
final CompositeType cidType = (CompositeType) idType;
// NOTE: the term `isEmbedded` here uses Hibernate's older (pre-JPA) naming for its "non-aggregated"
// composite-id support. It unfortunately conflicts with the JPA usage of "embedded". Here we normalize
// the legacy naming to the more descriptive encapsulated versus non-encapsulated phrasing
final boolean encapsulated = !cidType.isEmbedded();
if (encapsulated) {
// we have an `@EmbeddedId`
return MappingModelCreationHelper.buildEncapsulatedCompositeIdentifierMapping(this, bootEntityDescriptor.getIdentifierProperty(), bootEntityDescriptor.getIdentifierProperty().getName(), getTableName(), tableKeyColumns[0], cidType, creationProcess);
}
// otherwise we have a non-encapsulated composite-identifier
return generateNonEncapsulatedCompositeIdentifierMapping(creationProcess, bootEntityDescriptor);
}
final String columnDefinition;
final Long length;
final Integer precision;
final Integer scale;
if (bootEntityDescriptor.getIdentifier() == null) {
columnDefinition = null;
length = null;
precision = null;
scale = null;
} else {
Column column = bootEntityDescriptor.getIdentifier().getColumns().get(0);
columnDefinition = column.getSqlType();
length = column.getLength();
precision = column.getPrecision();
scale = column.getScale();
}
return new BasicEntityIdentifierMappingImpl(this, templateInstanceCreator, bootEntityDescriptor.getIdentifierProperty().getName(), getTableName(), tableKeyColumns[0][0], columnDefinition, length, precision, scale, (BasicType<?>) idType, creationProcess);
}
use of org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl in project hibernate-orm by hibernate.
the class AccessMappingTest method testExplicitPropertyAccessAnnotationsOnProperty.
@Test
public void testExplicitPropertyAccessAnnotationsOnProperty() throws Exception {
Configuration cfg = new Configuration();
Class<?> classUnderTest = Course2.class;
cfg.addAnnotatedClass(classUnderTest);
cfg.addAnnotatedClass(Student.class);
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
try {
final EntityPersister entityPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(classUnderTest.getName());
final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping();
assertTrue("Property access should be used.", identifierMapping.getPropertyAccess().getGetter() instanceof GetterMethodImpl);
} finally {
factory.close();
}
}
use of org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl in project hibernate-orm by hibernate.
the class AccessMappingTest method testDefaultFieldAccessIsInherited.
@Test
public void testDefaultFieldAccessIsInherited() {
Configuration cfg = new Configuration();
Class<?> classUnderTest = User.class;
cfg.addAnnotatedClass(classUnderTest);
cfg.addAnnotatedClass(Person.class);
cfg.addAnnotatedClass(Being.class);
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
try {
final EntityPersister entityPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(classUnderTest.getName());
final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping();
assertTrue("Field access should be used since the default access mode gets inherited", identifierMapping.getPropertyAccess().getGetter() instanceof GetterFieldImpl);
} finally {
factory.close();
}
}
use of org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl in project hibernate-orm by hibernate.
the class AccessMappingTest method testExplicitPropertyAccessAnnotationsWithJpaStyleOverride.
@Test
public void testExplicitPropertyAccessAnnotationsWithJpaStyleOverride() {
Configuration cfg = new Configuration();
Class<?> classUnderTest = Course5.class;
cfg.addAnnotatedClass(classUnderTest);
cfg.addAnnotatedClass(Student.class);
SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
try {
final EntityPersister entityPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(classUnderTest.getName());
final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping();
assertTrue("Field access should be used.", identifierMapping.getPropertyAccess().getGetter() instanceof GetterFieldImpl);
assertTrue("Property access should be used.", entityPersister.getAttributeMapping(0).getPropertyAccess().getGetter() instanceof GetterMethodImpl);
} finally {
factory.close();
}
}
Aggregations