Search in sources :

Example 6 with OrderColumn

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

the class CollectionBinder method determineCollectionClassification.

private static CollectionClassification determineCollectionClassification(Class<?> semanticJavaType, XProperty property, MetadataBuildingContext buildingContext) {
    if (semanticJavaType.isArray()) {
        return CollectionClassification.ARRAY;
    } else if (property.isAnnotationPresent(CollectionId.class) || property.isAnnotationPresent(CollectionIdJdbcType.class) || property.isAnnotationPresent(CollectionIdJdbcTypeCode.class) || property.isAnnotationPresent(CollectionIdJavaType.class)) {
        // explicitly an ID_BAG
        return CollectionClassification.ID_BAG;
    } else if (java.util.List.class.isAssignableFrom(semanticJavaType)) {
        if (property.isAnnotationPresent(OrderColumn.class) || property.isAnnotationPresent(org.hibernate.annotations.IndexColumn.class) || property.isAnnotationPresent(ListIndexBase.class) || property.isAnnotationPresent(ListIndexJdbcType.class) || property.isAnnotationPresent(ListIndexJdbcTypeCode.class) || property.isAnnotationPresent(ListIndexJavaType.class)) {
            // it is implicitly a LIST because of presence of explicit List index config
            return CollectionClassification.LIST;
        }
        if (property.isAnnotationPresent(jakarta.persistence.OrderBy.class) || property.isAnnotationPresent(OrderBy.class)) {
            return CollectionClassification.BAG;
        }
        ManyToMany manyToMany = property.getAnnotation(ManyToMany.class);
        if (manyToMany != null && !StringHelper.isEmpty(manyToMany.mappedBy())) {
            // We don't support @OrderColumn on the non-owning side of a many-to-many association.
            return CollectionClassification.BAG;
        }
        OneToMany oneToMany = property.getAnnotation(OneToMany.class);
        if (oneToMany != null && !StringHelper.isEmpty(oneToMany.mappedBy())) {
            // Unowned to-many mappings are always considered BAG by default
            return CollectionClassification.BAG;
        }
        // otherwise, return the implicit classification for List attributes
        return buildingContext.getBuildingOptions().getMappingDefaults().getImplicitListClassification();
    } else if (java.util.SortedSet.class.isAssignableFrom(semanticJavaType)) {
        return CollectionClassification.SORTED_SET;
    } else if (java.util.Set.class.isAssignableFrom(semanticJavaType)) {
        return CollectionClassification.SET;
    } else if (java.util.SortedMap.class.isAssignableFrom(semanticJavaType)) {
        return CollectionClassification.SORTED_MAP;
    } else if (java.util.Map.class.isAssignableFrom(semanticJavaType)) {
        return CollectionClassification.MAP;
    } else if (java.util.Collection.class.isAssignableFrom(semanticJavaType)) {
        if (property.isAnnotationPresent(CollectionId.class)) {
            return CollectionClassification.ID_BAG;
        } else {
            return CollectionClassification.BAG;
        }
    } else {
        return null;
    }
}
Also used : OrderBy(org.hibernate.annotations.OrderBy) CollectionIdJdbcTypeCode(org.hibernate.annotations.CollectionIdJdbcTypeCode) ListIndexJavaType(org.hibernate.annotations.ListIndexJavaType) OrderColumn(jakarta.persistence.OrderColumn) ManyToMany(jakarta.persistence.ManyToMany) ListIndexJdbcType(org.hibernate.annotations.ListIndexJdbcType) OneToMany(jakarta.persistence.OneToMany) IndexColumn(org.hibernate.cfg.IndexColumn) CollectionId(org.hibernate.annotations.CollectionId) LazyCollection(org.hibernate.annotations.LazyCollection) ElementCollection(jakarta.persistence.ElementCollection) Collection(org.hibernate.mapping.Collection)

Example 7 with OrderColumn

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

the class Ejb3XmlElementCollectionTest method testOrderColumnAllAttributes.

@Test
public void testOrderColumnAllAttributes() throws Exception {
    reader = getReader(Entity2.class, "field1", "element-collection.orm4.xml");
    assertAnnotationPresent(ElementCollection.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(jakarta.persistence.OrderColumn) Test(org.junit.Test)

Example 8 with OrderColumn

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

the class Ejb3XmlOneToManyTest method testOrderColumnNoAttributes.

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

Example 9 with OrderColumn

use of jakarta.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(jakarta.persistence.OrderColumn) Test(org.junit.Test)

Aggregations

OrderColumn (jakarta.persistence.OrderColumn)9 Test (org.junit.Test)6 ElementCollection (jakarta.persistence.ElementCollection)2 JoinColumn (jakarta.persistence.JoinColumn)2 ManyToMany (jakarta.persistence.ManyToMany)2 OneToMany (jakarta.persistence.OneToMany)2 OrderBy (org.hibernate.annotations.OrderBy)2 Embedded (jakarta.persistence.Embedded)1 IdClass (jakarta.persistence.IdClass)1 JoinColumns (jakarta.persistence.JoinColumns)1 MapKey (jakarta.persistence.MapKey)1 MapKeyJoinColumn (jakarta.persistence.MapKeyJoinColumn)1 MapKeyJoinColumns (jakarta.persistence.MapKeyJoinColumns)1 PrimaryKeyJoinColumn (jakarta.persistence.PrimaryKeyJoinColumn)1 PrimaryKeyJoinColumns (jakarta.persistence.PrimaryKeyJoinColumns)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AnnotationException (org.hibernate.AnnotationException)1 BatchSize (org.hibernate.annotations.BatchSize)1