Search in sources :

Example 41 with Collection

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

the class ListMappingTest method testOrderColumnInNormalBiDirectonalModel.

@Test
public void testOrderColumnInNormalBiDirectonalModel() {
    Metadata metadata = new MetadataSources(ssr).addAnnotatedClass(Order.class).addAnnotatedClass(LineItem.class).buildMetadata();
    Collection lineItemsBinding = metadata.getCollectionBindings().iterator().next();
    // make sure it was interpreted as a List (aka, as having an OrderColumn at all)
    assertThat(lineItemsBinding, instanceOf(org.hibernate.mapping.List.class));
    org.hibernate.mapping.List asList = (org.hibernate.mapping.List) lineItemsBinding;
    // assert the OrderColumn details
    final Column positionColumn = (Column) asList.getIndex().getColumnIterator().next();
    assertThat(positionColumn.getName(), equalTo("position"));
    // make sure the OrderColumn is part of the collection table
    assertTrue(asList.getCollectionTable().containsColumn(positionColumn));
    class TargetImpl extends GenerationTargetToStdout {

        boolean found = false;

        @Override
        public void accept(String action) {
            super.accept(action);
            if (action.startsWith("create table t_line_item")) {
                if (action.contains("position")) {
                    found = true;
                }
            }
        }
    }
    TargetImpl target = new TargetImpl();
    new SchemaCreatorImpl(ssr).doCreation(metadata, true, target);
    assertTrue(target.found);
}
Also used : GenerationTargetToStdout(org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout) Metadata(org.hibernate.boot.Metadata) MetadataSources(org.hibernate.boot.MetadataSources) SchemaCreatorImpl(org.hibernate.tool.schema.internal.SchemaCreatorImpl) JoinColumn(javax.persistence.JoinColumn) Column(org.hibernate.mapping.Column) OrderColumn(javax.persistence.OrderColumn) Collection(org.hibernate.mapping.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

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

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