Search in sources :

Example 21 with Collection

use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.

the class BaseNamingTests method validateCustomerRegisteredTrademarks.

protected void validateCustomerRegisteredTrademarks(Metadata metadata) {
    final Collection collectionBinding = metadata.getCollectionBinding(Customer.class.getName() + ".registeredTrademarks");
    assertNotNull(collectionBinding);
    validateCustomerRegisteredTrademarksTableName(collectionBinding.getCollectionTable().getQuotedName());
    assertEquals(1, collectionBinding.getKey().getColumnSpan());
    validateCustomerRegisteredTrademarksKeyColumn((Column) collectionBinding.getKey().getColumnIterator().next());
    assertEquals(1, collectionBinding.getElement().getColumnSpan());
    validateCustomerRegisteredTrademarksElementColumn((Column) collectionBinding.getElement().getColumnIterator().next());
}
Also used : Collection(org.hibernate.mapping.Collection)

Example 22 with Collection

use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.

the class BaseNamingTests method validateCustomerAddresses.

protected void validateCustomerAddresses(Metadata metadata) {
    final Collection collectionBinding = metadata.getCollectionBinding(Customer.class.getName() + ".addresses");
    assertNotNull(collectionBinding);
    validateCustomerAddressesTableName(collectionBinding.getCollectionTable().getQuotedName());
    assertEquals(1, collectionBinding.getKey().getColumnSpan());
    validateCustomerAddressesKeyColumn((Column) collectionBinding.getKey().getColumnIterator().next());
    assertEquals(3, collectionBinding.getElement().getColumnSpan());
    validateCustomerAddressesElementComponent(assertTyping(Component.class, collectionBinding.getElement()));
}
Also used : Collection(org.hibernate.mapping.Collection) Component(org.hibernate.mapping.Component)

Example 23 with Collection

use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.

the class BaseNamingTests method validateCustomerOrders.

protected void validateCustomerOrders(Metadata metadata) {
    final Collection collectionBinding = metadata.getCollectionBinding(Customer.class.getName() + ".orders");
    assertNotNull(collectionBinding);
    validateCustomerOrdersTableName(collectionBinding.getCollectionTable().getQuotedName());
    assertEquals(1, collectionBinding.getKey().getColumnSpan());
    validateCustomerOrdersKeyColumn((Column) collectionBinding.getKey().getColumnIterator().next());
    assertEquals(1, collectionBinding.getElement().getColumnSpan());
    validateCustomerOrdersElementColumn((Column) collectionBinding.getElement().getColumnIterator().next());
}
Also used : Collection(org.hibernate.mapping.Collection)

Example 24 with Collection

use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.

the class CorrectnessTestCase method buildMetadata.

private Metadata buildMetadata(StandardServiceRegistry registry) {
    MetadataSources metadataSources = new MetadataSources(registry);
    for (Class entityClass : getAnnotatedClasses()) {
        metadataSources.addAnnotatedClass(entityClass);
    }
    Metadata metadata = metadataSources.buildMetadata();
    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited()) {
            ((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
        }
    }
    // Collections don't have integrated version, these piggyback on parent's owner version (for DB).
    // However, this version number isn't extractable and is not passed to cache methods.
    AccessType collectionAccessType = accessType == AccessType.NONSTRICT_READ_WRITE ? AccessType.READ_WRITE : accessType;
    for (Collection collectionBinding : metadata.getCollectionBindings()) {
        collectionBinding.setCacheConcurrencyStrategy(collectionAccessType.getExternalName());
    }
    return metadata;
}
Also used : RootClass(org.hibernate.mapping.RootClass) MetadataSources(org.hibernate.boot.MetadataSources) Metadata(org.hibernate.boot.Metadata) Collection(org.hibernate.mapping.Collection) PersistentClass(org.hibernate.mapping.PersistentClass) RootClass(org.hibernate.mapping.RootClass) AccessType(org.hibernate.cache.spi.access.AccessType) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 25 with Collection

use of org.hibernate.mapping.Collection in project hibernate-orm by hibernate.

the class SubselectFetchWithFormulaTest method checkSubselectWithFormula.

@Test
public void checkSubselectWithFormula() throws Exception {
    // as a pre-condition make sure that subselect fetching is enabled for the collection...
    Collection collectionBinding = metadata().getCollectionBinding(Name.class.getName() + ".values");
    assertThat(collectionBinding.isSubselectLoadable(), is(true));
    // Now force the subselect fetch and make sure we do not get SQL errors
    Session session = openSession();
    session.getTransaction().begin();
    List results = session.createCriteria(Name.class).list();
    for (Object result : results) {
        Name name = (Name) result;
        name.getValues().size();
    }
    session.getTransaction().commit();
    session.close();
}
Also used : Collection(org.hibernate.mapping.Collection) List(java.util.List) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

Collection (org.hibernate.mapping.Collection)42 PersistentClass (org.hibernate.mapping.PersistentClass)19 Test (org.junit.Test)15 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 RootClass (org.hibernate.mapping.RootClass)6 AnnotationException (org.hibernate.AnnotationException)5 SimpleValue (org.hibernate.mapping.SimpleValue)5 TestForIssue (org.hibernate.testing.TestForIssue)5 List (java.util.List)4 Map (java.util.Map)4 ElementCollection (javax.persistence.ElementCollection)4 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)4 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)4 Value (org.hibernate.mapping.Value)4 ArrayList (java.util.ArrayList)3