Search in sources :

Example 6 with OrderColumn

use of javax.persistence.OrderColumn in project hibernate-orm by hibernate.

the class Ejb3XmlOneToManyTest method testOrderColumnAllAttributes.

@Test
public void testOrderColumnAllAttributes() throws Exception {
    reader = getReader(Entity2.class, "field1", "one-to-many.orm4.xml");
    assertAnnotationPresent(OneToMany.class);
    assertAnnotationNotPresent(OrderBy.class);
    assertAnnotationPresent(OrderColumn.class);
    OrderColumn orderColumnAnno = reader.getAnnotation(OrderColumn.class);
    assertEquals("int", orderColumnAnno.columnDefinition());
    assertEquals("col1", orderColumnAnno.name());
    assertFalse(orderColumnAnno.insertable());
    assertFalse(orderColumnAnno.nullable());
    assertFalse(orderColumnAnno.updatable());
}
Also used : OrderColumn(javax.persistence.OrderColumn) Test(org.junit.Test)

Example 7 with OrderColumn

use of javax.persistence.OrderColumn 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.matches("^create( (column|row))? 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)

Aggregations

OrderColumn (javax.persistence.OrderColumn)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JoinColumn (javax.persistence.JoinColumn)1 Metadata (org.hibernate.boot.Metadata)1 MetadataSources (org.hibernate.boot.MetadataSources)1 Collection (org.hibernate.mapping.Collection)1 Column (org.hibernate.mapping.Column)1 SchemaCreatorImpl (org.hibernate.tool.schema.internal.SchemaCreatorImpl)1 GenerationTargetToStdout (org.hibernate.tool.schema.internal.exec.GenerationTargetToStdout)1