use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class CollectionJoinTableNamingTest method testCollectionJoinTableNamingLegacyHbmStrategy.
@Test
@TestForIssue(jiraKey = "HHH-9908")
public void testCollectionJoinTableNamingLegacyHbmStrategy() {
final MetadataSources metadataSources = new MetadataSources();
try {
metadataSources.addAnnotatedClass(Input.class);
metadataSources.addAnnotatedClass(Ptx.class);
final Metadata metadata = metadataSources.getMetadataBuilder().applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyHbmImpl.INSTANCE).build();
Collection inputs1Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs1");
assertEquals("ptx_inputs1", inputs1Mapping.getCollectionTable().getName());
Collection inputs2Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs2");
assertEquals("ptx_inputs2", inputs2Mapping.getCollectionTable().getName());
} finally {
ServiceRegistry metaServiceRegistry = metadataSources.getServiceRegistry();
if (metaServiceRegistry instanceof BootstrapServiceRegistry) {
BootstrapServiceRegistryBuilder.destroy(metaServiceRegistry);
}
}
}
use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class CollectionJoinTableNamingTest method assertSameTableUsed.
private void assertSameTableUsed(Metadata metadata) {
Collection inputs1Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs1");
assertEquals("ptx_input", inputs1Mapping.getCollectionTable().getName());
Collection inputs2Mapping = metadata.getCollectionBinding(Ptx.class.getName() + ".inputs2");
assertEquals("ptx_input", inputs2Mapping.getCollectionTable().getName());
assertSame(inputs1Mapping.getCollectionTable(), inputs2Mapping.getCollectionTable());
// NOTE : here so that tester can more easily see the produced table. It is only dumped to stdout
new SchemaExport().create(EnumSet.of(TargetType.STDOUT), metadata);
for (int i = 0; i < inputs1Mapping.getCollectionTable().getColumnSpan(); i++) {
final Column column = inputs1Mapping.getCollectionTable().getColumn(i);
// this, coupled with JPA saying the 2 collections implicitly map to the same table,
// is the crux of the problem: all columns are null, so we effectively can never
// insert rows into it.
assertFalse(column.isNullable());
}
}
use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class BaseNamingTests method validateCustomerIndustries.
protected void validateCustomerIndustries(Metadata metadata) {
final Collection collectionBinding = metadata.getCollectionBinding(Customer.class.getName() + ".industries");
assertNotNull(collectionBinding);
validateCustomerIndustriesTableName(collectionBinding.getCollectionTable().getQuotedName());
assertEquals(1, collectionBinding.getKey().getColumnSpan());
validateCustomerIndustriesKeyColumn((Column) collectionBinding.getKey().getColumnIterator().next());
assertEquals(1, collectionBinding.getElement().getColumnSpan());
validateCustomerIndustriesElementColumn((Column) collectionBinding.getElement().getColumnIterator().next());
}
use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class SortTest method testSortedSetDefinitionInHbmXml.
@Test
public void testSortedSetDefinitionInHbmXml() {
final PersistentClass entityMapping = metadata().getEntityBinding(Search.class.getName());
final Property sortedSetProperty = entityMapping.getProperty("searchResults");
final Collection sortedSetMapping = assertTyping(Collection.class, sortedSetProperty.getValue());
assertTrue("SortedSet mapping not interpreted as sortable", sortedSetMapping.isSorted());
final Property sortedMapProperty = entityMapping.getProperty("tokens");
final Collection sortedMapMapping = assertTyping(Collection.class, sortedMapProperty.getValue());
assertTrue("SortedMap mapping not interpreted as sortable", sortedMapMapping.isSorted());
}
use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.
the class InFlightMetadataCollectorImpl method processCachingOverrides.
private void processCachingOverrides() {
if (bootstrapContext.getCacheRegionDefinitions() == null) {
return;
}
for (CacheRegionDefinition cacheRegionDefinition : bootstrapContext.getCacheRegionDefinitions()) {
if (cacheRegionDefinition.getRegionType() == CacheRegionDefinition.CacheRegionType.ENTITY) {
final PersistentClass entityBinding = getEntityBinding(cacheRegionDefinition.getRole());
if (entityBinding == null) {
throw new HibernateException("Cache override referenced an unknown entity : " + cacheRegionDefinition.getRole());
}
if (!RootClass.class.isInstance(entityBinding)) {
throw new HibernateException("Cache override referenced a non-root entity : " + cacheRegionDefinition.getRole());
}
entityBinding.setCached(true);
((RootClass) entityBinding).setCacheRegionName(cacheRegionDefinition.getRegion());
((RootClass) entityBinding).setCacheConcurrencyStrategy(cacheRegionDefinition.getUsage());
((RootClass) entityBinding).setLazyPropertiesCacheable(cacheRegionDefinition.isCacheLazy());
} else if (cacheRegionDefinition.getRegionType() == CacheRegionDefinition.CacheRegionType.COLLECTION) {
final Collection collectionBinding = getCollectionBinding(cacheRegionDefinition.getRole());
if (collectionBinding == null) {
throw new HibernateException("Cache override referenced an unknown collection role : " + cacheRegionDefinition.getRole());
}
collectionBinding.setCacheRegionName(cacheRegionDefinition.getRegion());
collectionBinding.setCacheConcurrencyStrategy(cacheRegionDefinition.getUsage());
}
}
}
Aggregations