use of org.hibernate.metamodel.RuntimeMetamodels in project hibernate-orm by hibernate.
the class EntityHidingTests method testModel.
@Test
@NotImplementedYet(reason = "Contributed entity hiding is not yet implemented", strict = false)
public void testModel(SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final RuntimeMetamodels runtimeMetamodels = sessionFactory.getRuntimeMetamodels();
final EntityDomainType<Object> jpaModelDescriptor = runtimeMetamodels.getJpaMetamodel().entity("DynamicEntity");
assertThat(jpaModelDescriptor, nullValue());
final EntityPersister mappingModelDescriptor = runtimeMetamodels.getMappingMetamodel().findEntityDescriptor("DynamicEntity");
assertThat(mappingModelDescriptor, nullValue());
}
use of org.hibernate.metamodel.RuntimeMetamodels in project hibernate-orm by hibernate.
the class AbstractManagedType method isCompatible.
private boolean isCompatible(PersistentAttribute<?, ?> attribute1, PersistentAttribute<?, ?> attribute2) {
if (attribute1 == attribute2) {
return true;
}
final RuntimeMetamodels runtimeMetamodels = jpaMetamodel().getTypeConfiguration().getSessionFactory().getRuntimeMetamodels();
final EntityMappingType entity1 = runtimeMetamodels.getEntityMappingType(attribute1.getDeclaringType().getTypeName());
final EntityMappingType entity2 = runtimeMetamodels.getEntityMappingType(attribute2.getDeclaringType().getTypeName());
return entity1 != null && entity2 != null && MappingModelHelper.isCompatibleModelPart(entity1.findSubPart(attribute1.getName()), entity2.findSubPart(attribute2.getName()));
}
use of org.hibernate.metamodel.RuntimeMetamodels in project hibernate-orm by hibernate.
the class ImmutableManyToOneNaturalIdAnnotationTest method testNaturalIdNullability.
@Test
@TestForIssue(jiraKey = "HHH-10360")
public void testNaturalIdNullability(SessionFactoryScope scope) {
// nullability is not specified for either properties making up
// the natural ID, so they should be nullable by annotation-specific default
final RuntimeMetamodels runtimeMetamodels = scope.getSessionFactory().getRuntimeMetamodels();
final EntityMappingType childMapping = runtimeMetamodels.getEntityMappingType(Child.class.getName());
final EntityPersister persister = childMapping.getEntityPersister();
final EntityMetamodel entityMetamodel = persister.getEntityMetamodel();
final int nameIndex = entityMetamodel.getPropertyIndex("name");
final int parentIndex = entityMetamodel.getPropertyIndex("parent");
// checking alphabetic sort in relation to EntityPersister/EntityMetamodel
assertThat(nameIndex, lessThan(parentIndex));
assertFalse(persister.getPropertyUpdateability()[nameIndex]);
assertFalse(persister.getPropertyUpdateability()[parentIndex]);
assertTrue(persister.getPropertyNullability()[nameIndex]);
assertTrue(persister.getPropertyNullability()[parentIndex]);
final NaturalIdMapping naturalIdMapping = childMapping.getNaturalIdMapping();
assertNotNull(naturalIdMapping);
assertThat(naturalIdMapping.getNaturalIdAttributes().size(), is(2));
// access by list-index should again be alphabetically sorted
final SingularAttributeMapping first = naturalIdMapping.getNaturalIdAttributes().get(0);
assertThat(first.getAttributeName(), is("name"));
final StateArrayContributorMetadata firstMetadata = first.getAttributeMetadataAccess().resolveAttributeMetadata(null);
assertFalse(firstMetadata.getMutabilityPlan().isMutable());
final SingularAttributeMapping second = naturalIdMapping.getNaturalIdAttributes().get(1);
assertThat(second.getAttributeName(), is("parent"));
final StateArrayContributorMetadata secondMetadata = second.getAttributeMetadataAccess().resolveAttributeMetadata(null);
assertFalse(secondMetadata.getMutabilityPlan().isMutable());
}
use of org.hibernate.metamodel.RuntimeMetamodels in project hibernate-orm by hibernate.
the class Builders method attributeResult.
public static ResultBuilder attributeResult(String columnAlias, String entityName, String attributePath, SessionFactoryImplementor sessionFactory) {
if (attributePath.contains(".")) {
throw new NotYetImplementedFor6Exception("Support for defining a NativeQuery attribute result based on a composite path is not yet implemented");
}
final RuntimeMetamodels runtimeMetamodels = sessionFactory.getRuntimeMetamodels();
final String fullEntityName = runtimeMetamodels.getMappingMetamodel().getImportedName(entityName);
final EntityPersister entityMapping = runtimeMetamodels.getMappingMetamodel().findEntityDescriptor(fullEntityName);
if (entityMapping == null) {
throw new IllegalArgumentException("Could not locate entity mapping : " + fullEntityName);
}
final AttributeMapping attributeMapping = entityMapping.findAttributeMapping(attributePath);
if (attributeMapping == null) {
throw new IllegalArgumentException("Could not locate attribute mapping : " + fullEntityName + "." + attributePath);
}
if (attributeMapping instanceof SingularAttributeMapping) {
final SingularAttributeMapping singularAttributeMapping = (SingularAttributeMapping) attributeMapping;
return new DynamicResultBuilderAttribute(singularAttributeMapping, columnAlias, fullEntityName, attributePath);
}
throw new IllegalArgumentException(String.format(Locale.ROOT, "Specified attribute mapping [%s.%s] not a basic attribute: %s", fullEntityName, attributePath, attributeMapping));
}
use of org.hibernate.metamodel.RuntimeMetamodels in project hibernate-orm by hibernate.
the class Builders method entityCalculated.
/**
* Creates a EntityResultBuilder that does not allow any further configuring of the mapping.
*
* @see #entityCalculated(String, String, SessionFactoryImplementor)
* @see NativeQuery#addEntity(String, Class, LockMode)
* @see NativeQuery#addEntity(String, String, LockMode)
*/
public static DynamicResultBuilderEntityCalculated entityCalculated(String tableAlias, String entityName, LockMode explicitLockMode, SessionFactoryImplementor sessionFactory) {
final RuntimeMetamodels runtimeMetamodels = sessionFactory.getRuntimeMetamodels();
final EntityMappingType entityMapping = runtimeMetamodels.getEntityMappingType(entityName);
return new DynamicResultBuilderEntityCalculated(entityMapping, tableAlias, explicitLockMode, sessionFactory);
}
Aggregations