use of org.hibernate.metamodel.MappingMetamodel in project hibernate-orm by hibernate.
the class AbstractEntityWithOneToManyTest method prepareTest.
@BeforeEach
protected void prepareTest(SessionFactoryScope scope) throws Exception {
SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
MappingMetamodel domainModel = sessionFactory.getRuntimeMetamodels().getMappingMetamodel();
isContractPartiesInverse = domainModel.getCollectionDescriptor(Contract.class.getName() + ".parties").isInverse();
try {
domainModel.getEntityDescriptor(Party.class.getName()).getPropertyType("contract");
isContractPartiesBidirectional = true;
} catch (QueryException ex) {
isContractPartiesBidirectional = false;
}
try {
domainModel.getEntityDescriptor(ContractVariation.class.getName()).getPropertyType("contract");
isContractVariationsBidirectional = true;
} catch (QueryException ex) {
isContractVariationsBidirectional = false;
}
isContractVersioned = domainModel.getEntityDescriptor(Contract.class.getName()).isVersioned();
}
use of org.hibernate.metamodel.MappingMetamodel in project hibernate-orm by hibernate.
the class PluralAttributeMappingTests method testLists.
@Test
public void testLists(SessionFactoryScope scope) {
final MappingMetamodel domainModel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor(EntityOfLists.class);
assertThat(containerEntityDescriptor.getNumberOfAttributeMappings(), is(8));
final AttributeMapping listOfBasics = containerEntityDescriptor.findAttributeMapping("listOfBasics");
assertThat(listOfBasics, notNullValue());
final AttributeMapping listOfEnums = containerEntityDescriptor.findAttributeMapping("listOfEnums");
assertThat(listOfEnums, notNullValue());
final AttributeMapping listOfConvertedBasics = containerEntityDescriptor.findAttributeMapping("listOfConvertedEnums");
assertThat(listOfConvertedBasics, notNullValue());
final AttributeMapping listOfComponents = containerEntityDescriptor.findAttributeMapping("listOfComponents");
assertThat(listOfComponents, notNullValue());
final AttributeMapping listOfOneToMany = containerEntityDescriptor.findAttributeMapping("listOfOneToMany");
assertThat(listOfOneToMany, notNullValue());
final AttributeMapping listOfManyToMany = containerEntityDescriptor.findAttributeMapping("listOfManyToMany");
assertThat(listOfManyToMany, notNullValue());
}
use of org.hibernate.metamodel.MappingMetamodel in project hibernate-orm by hibernate.
the class PluralAttributeMappingTests method testMaps.
@Test
public void testMaps(SessionFactoryScope scope) {
final MappingMetamodel domainModel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
final EntityMappingType containerEntityDescriptor = domainModel.getEntityDescriptor(EntityOfMaps.class);
assertThat(containerEntityDescriptor.getNumberOfAttributeMappings(), is(17));
final PluralAttributeMapping basicByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByBasic");
assertThat(basicByBasic, notNullValue());
assertThat(basicByBasic.getKeyDescriptor(), notNullValue());
assertThat(basicByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping sortedBasicByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("sortedBasicByBasic");
assertThat(sortedBasicByBasic, notNullValue());
assertThat(sortedBasicByBasic.getKeyDescriptor(), notNullValue());
assertThat(sortedBasicByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping sortedBasicByBasicWithSortNaturalByDefault = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("sortedBasicByBasicWithSortNaturalByDefault");
assertThat(sortedBasicByBasicWithSortNaturalByDefault, notNullValue());
assertThat(sortedBasicByBasicWithSortNaturalByDefault.getKeyDescriptor(), notNullValue());
assertThat(sortedBasicByBasicWithSortNaturalByDefault.getElementDescriptor(), notNullValue());
final PluralAttributeMapping basicByEnum = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByEnum");
assertThat(basicByEnum, notNullValue());
assertThat(basicByEnum.getKeyDescriptor(), notNullValue());
assertThat(basicByEnum.getElementDescriptor(), notNullValue());
final PluralAttributeMapping basicByConvertedEnum = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByConvertedEnum");
assertThat(basicByConvertedEnum, notNullValue());
assertThat(basicByConvertedEnum.getKeyDescriptor(), notNullValue());
assertThat(basicByConvertedEnum.getElementDescriptor(), notNullValue());
final PluralAttributeMapping someStuffByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("componentByBasic");
assertThat(someStuffByBasic, notNullValue());
assertThat(someStuffByBasic.getKeyDescriptor(), notNullValue());
assertThat(someStuffByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping basicBySomeStuff = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByComponent");
assertThat(basicBySomeStuff, notNullValue());
assertThat(basicBySomeStuff.getKeyDescriptor(), notNullValue());
assertThat(basicBySomeStuff.getElementDescriptor(), notNullValue());
final PluralAttributeMapping oneToManyByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("oneToManyByBasic");
assertThat(oneToManyByBasic, notNullValue());
assertThat(oneToManyByBasic.getKeyDescriptor(), notNullValue());
assertThat(oneToManyByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping basicByOneToMany = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("basicByOneToMany");
assertThat(basicByOneToMany, notNullValue());
assertThat(basicByOneToMany.getKeyDescriptor(), notNullValue());
assertThat(basicByOneToMany.getElementDescriptor(), notNullValue());
final PluralAttributeMapping manyToManyByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("manyToManyByBasic");
assertThat(manyToManyByBasic, notNullValue());
assertThat(manyToManyByBasic.getKeyDescriptor(), notNullValue());
assertThat(manyToManyByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping sortedManyToManyByBasic = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("sortedManyToManyByBasic");
assertThat(sortedManyToManyByBasic, notNullValue());
assertThat(sortedManyToManyByBasic.getKeyDescriptor(), notNullValue());
assertThat(sortedManyToManyByBasic.getElementDescriptor(), notNullValue());
final PluralAttributeMapping sortedManyToManyByBasicWithSortNaturalByDefault = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("sortedManyToManyByBasicWithSortNaturalByDefault");
assertThat(sortedManyToManyByBasicWithSortNaturalByDefault, notNullValue());
assertThat(sortedManyToManyByBasicWithSortNaturalByDefault.getKeyDescriptor(), notNullValue());
assertThat(sortedManyToManyByBasicWithSortNaturalByDefault.getElementDescriptor(), notNullValue());
final PluralAttributeMapping componentByBasicOrdered = (PluralAttributeMapping) containerEntityDescriptor.findAttributeMapping("componentByBasicOrdered");
assertThat(componentByBasicOrdered, notNullValue());
assertThat(componentByBasicOrdered.getKeyDescriptor(), notNullValue());
assertThat(componentByBasicOrdered.getElementDescriptor(), notNullValue());
assertThat(componentByBasicOrdered.getOrderByFragment(), notNullValue());
}
use of org.hibernate.metamodel.MappingMetamodel in project hibernate-orm by hibernate.
the class UUIDCharTest method testUsage.
@Test
public void testUsage(SessionFactoryScope scope) {
final MappingMetamodel domainModel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
final EntityPersister entityDescriptor = domainModel.findEntityDescriptor(Node.class);
final List<JdbcMapping> identifierJdbcMappings = entityDescriptor.getIdentifierMapping().getJdbcMappings();
assertThat(identifierJdbcMappings, hasSize(1));
final JdbcMapping jdbcMapping = identifierJdbcMappings.get(0);
assertThat(jdbcMapping.getJdbcType().isString(), is(true));
final UUIDPair uuidPair = scope.fromTransaction(session -> {
final Node root = new Node("root");
session.save(root);
assertThat(root.id, notNullValue());
final Node child = new Node("child", root);
session.save(child);
assertThat(child.id, notNullValue());
return new UUIDPair(root.id, child.id);
});
scope.inTransaction(session -> {
final Node root = session.get(Node.class, uuidPair.rootId);
assertThat(root, notNullValue());
final Node child = session.get(Node.class, uuidPair.childId);
assertThat(child, notNullValue());
});
scope.inTransaction(session -> {
final Node node = session.createQuery("from Node n join fetch n.parent where n.parent is not null", Node.class).uniqueResult();
assertThat(node, notNullValue());
assertThat(node.parent, notNullValue());
});
}
use of org.hibernate.metamodel.MappingMetamodel in project hibernate-orm by hibernate.
the class MetamodelBoundedCacheTest method testMemoryConsumptionOfFailedImportsCache.
@Test
@TestForIssue(jiraKey = "HHH-14948")
public void testMemoryConsumptionOfFailedImportsCache() throws NoSuchFieldException, IllegalAccessException {
MappingMetamodel mappingMetamodel = sessionFactory().getMappingMetamodel();
MappingMetamodelImpl mImpl = (MappingMetamodelImpl) mappingMetamodel;
final JpaMetamodel jpaMetamodel = mImpl.getJpaMetamodel();
for (int i = 0; i < 1001; i++) {
jpaMetamodel.qualifyImportableName("nonexistend" + i);
}
Field field = JpaMetamodelImpl.class.getDeclaredField("nameToImportMap");
field.setAccessible(true);
// noinspection unchecked
Map<String, String> imports = (Map<String, String>) field.get(jpaMetamodel);
// VERY hard-coded, but considering the possibility of a regression of a memory-related issue,
// it should be worth it
assertEquals(1000, imports.size());
}
Aggregations