Search in sources :

Example 81 with Collection

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);
        }
    }
}
Also used : MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Collection(org.hibernate.mapping.Collection) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) ServiceRegistry(org.hibernate.service.ServiceRegistry) BootstrapServiceRegistry(org.hibernate.boot.registry.BootstrapServiceRegistry) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 82 with Collection

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());
    }
}
Also used : Column(org.hibernate.mapping.Column) OrderColumn(javax.persistence.OrderColumn) Collection(org.hibernate.mapping.Collection) SchemaExport(org.hibernate.tool.hbm2ddl.SchemaExport)

Example 83 with Collection

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());
}
Also used : Collection(org.hibernate.mapping.Collection)

Example 84 with Collection

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());
}
Also used : Collection(org.hibernate.mapping.Collection) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 85 with Collection

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());
        }
    }
}
Also used : RootClass(org.hibernate.mapping.RootClass) HibernateException(org.hibernate.HibernateException) CacheRegionDefinition(org.hibernate.boot.CacheRegionDefinition) Collection(org.hibernate.mapping.Collection) IdentifierCollection(org.hibernate.mapping.IdentifierCollection) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

Collection (org.hibernate.mapping.Collection)134 Test (org.junit.jupiter.api.Test)80 Bag (org.hibernate.mapping.Bag)61 IdentifierBag (org.hibernate.mapping.IdentifierBag)61 SimpleValue (org.hibernate.mapping.SimpleValue)28 Table (org.hibernate.mapping.Table)27 Set (org.hibernate.mapping.Set)25 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)24 Test (org.junit.Test)23 PersistentClass (org.hibernate.mapping.PersistentClass)22 ManyToOne (org.hibernate.mapping.ManyToOne)14 KeyValue (org.hibernate.mapping.KeyValue)13 IValue (org.jboss.tools.hibernate.runtime.spi.IValue)12 Property (org.hibernate.mapping.Property)11 Metadata (org.hibernate.boot.Metadata)9 MetadataSources (org.hibernate.boot.MetadataSources)9 Column (org.hibernate.mapping.Column)9 Iterator (java.util.Iterator)7 Component (org.hibernate.mapping.Component)7 AbstractValueFacade (org.jboss.tools.hibernate.runtime.common.AbstractValueFacade)7