Search in sources :

Example 71 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)

Example 72 with Collection

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

the class SubselectFetchWithFormulaTransactSqlTest 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)

Example 73 with Collection

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

the class IndexedCollectionTest method isDefaultColumnPresent.

private boolean isDefaultColumnPresent(String collectionOwner, String propertyName, String suffix) {
    final Collection collection = metadata().getCollectionBinding(collectionOwner + "." + propertyName);
    final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
    boolean hasDefault = false;
    while (columnIterator.hasNext()) {
        Column column = (Column) columnIterator.next();
        if ((propertyName + suffix).equals(column.getName()))
            hasDefault = true;
    }
    return hasDefault;
}
Also used : Column(org.hibernate.mapping.Column) Iterator(java.util.Iterator) Collection(org.hibernate.mapping.Collection)

Example 74 with Collection

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

the class NonReflectiveBinderTest method testComparator.

@Test
public void testComparator() {
    PersistentClass cm = metadata.getEntityBinding("org.hibernate.test.legacy.Wicked");
    Property property = cm.getProperty("sortedEmployee");
    Collection col = (Collection) property.getValue();
    assertEquals(col.getComparatorClassName(), "org.hibernate.test.legacy.NonExistingComparator");
}
Also used : Collection(org.hibernate.mapping.Collection) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 75 with Collection

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

the class DefaultNamingCollectionElementTest method isCollectionColumnPresent.

private void isCollectionColumnPresent(String collectionOwner, String propertyName, String columnName) {
    final Collection collection = metadata().getCollectionBinding(collectionOwner + "." + propertyName);
    final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
    boolean hasDefault = false;
    while (columnIterator.hasNext()) {
        Column column = (Column) columnIterator.next();
        if (columnName.equals(column.getName()))
            hasDefault = true;
    }
    assertTrue("Could not find " + columnName, hasDefault);
}
Also used : Column(org.hibernate.mapping.Column) Iterator(java.util.Iterator) Collection(org.hibernate.mapping.Collection)

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