Search in sources :

Example 1 with MapKeyJoinColumn

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

the class AnnotationBinder method mapKeyColumns.

private static JoinColumn[] mapKeyColumns(PropertyHolder propertyHolder, PropertyData inferredData, EntityBinder entityBinder, MetadataBuildingContext context, XProperty property, CollectionBinder collectionBinder, Comment comment) {
    Column[] keyColumns = property.isAnnotationPresent(MapKeyColumn.class) ? new Column[] { new MapKeyColumnDelegator(property.getAnnotation(MapKeyColumn.class)) } : null;
    AnnotatedColumn[] mapColumns = buildColumnsFromAnnotations(keyColumns, comment, Nullability.FORCED_NOT_NULL, propertyHolder, inferredData, "_KEY", entityBinder.getSecondaryTables(), context);
    collectionBinder.setMapKeyColumns(mapColumns);
    JoinColumn[] joinKeyColumns = null;
    if (property.isAnnotationPresent(MapKeyJoinColumns.class)) {
        final MapKeyJoinColumn[] mapKeyJoinColumns = property.getAnnotation(MapKeyJoinColumns.class).value();
        joinKeyColumns = new JoinColumn[mapKeyJoinColumns.length];
        int index = 0;
        for (MapKeyJoinColumn joinColumn : mapKeyJoinColumns) {
            joinKeyColumns[index] = new MapKeyJoinColumnDelegator(joinColumn);
            index++;
        }
        if (property.isAnnotationPresent(MapKeyJoinColumn.class)) {
            throw new AnnotationException("@MapKeyJoinColumn and @MapKeyJoinColumns used on the same property: " + BinderHelper.getPath(propertyHolder, inferredData));
        }
    } else if (property.isAnnotationPresent(MapKeyJoinColumn.class)) {
        joinKeyColumns = new JoinColumn[] { new MapKeyJoinColumnDelegator(property.getAnnotation(MapKeyJoinColumn.class)) };
    }
    return joinKeyColumns;
}
Also used : MapKeyJoinColumnDelegator(org.hibernate.cfg.annotations.MapKeyJoinColumnDelegator) MapKeyJoinColumns(jakarta.persistence.MapKeyJoinColumns) MapKeyColumn(jakarta.persistence.MapKeyColumn) MapKeyColumnDelegator(org.hibernate.cfg.annotations.MapKeyColumnDelegator) UniqueConstraint(jakarta.persistence.UniqueConstraint) Constraint(org.hibernate.mapping.Constraint) MapKeyJoinColumn(jakarta.persistence.MapKeyJoinColumn) JoinColumn(jakarta.persistence.JoinColumn) PrimaryKeyJoinColumn(jakarta.persistence.PrimaryKeyJoinColumn) MapKeyJoinColumn(jakarta.persistence.MapKeyJoinColumn) MapKeyColumn(jakarta.persistence.MapKeyColumn) MapKeyJoinColumn(jakarta.persistence.MapKeyJoinColumn) JoinColumn(jakarta.persistence.JoinColumn) Column(jakarta.persistence.Column) PrimaryKeyJoinColumn(jakarta.persistence.PrimaryKeyJoinColumn) OrderColumn(jakarta.persistence.OrderColumn) DiscriminatorColumn(jakarta.persistence.DiscriminatorColumn) AnnotatedDiscriminatorColumn.buildDiscriminatorColumn(org.hibernate.cfg.AnnotatedDiscriminatorColumn.buildDiscriminatorColumn) AnnotationException(org.hibernate.AnnotationException)

Example 2 with MapKeyJoinColumn

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

the class JPAXMLOverriddenAnnotationReader method buildMapKeyJoinColumns.

private MapKeyJoinColumn[] buildMapKeyJoinColumns(List<JaxbMapKeyJoinColumn> elements) {
    List<MapKeyJoinColumn> joinColumns = new ArrayList<>();
    if (elements != null) {
        for (JaxbMapKeyJoinColumn element : elements) {
            AnnotationDescriptor column = new AnnotationDescriptor(MapKeyJoinColumn.class);
            copyAttribute(column, "name", element.getName(), false);
            copyAttribute(column, "referenced-column-name", element.getReferencedColumnName(), false);
            copyAttribute(column, "unique", element.isUnique(), false);
            copyAttribute(column, "nullable", element.isNullable(), false);
            copyAttribute(column, "insertable", element.isInsertable(), false);
            copyAttribute(column, "updatable", element.isUpdatable(), false);
            copyAttribute(column, "column-definition", element.getColumnDefinition(), false);
            copyAttribute(column, "table", element.getTable(), false);
            joinColumns.add(AnnotationFactory.create(column));
        }
    }
    return joinColumns.toArray(new MapKeyJoinColumn[joinColumns.size()]);
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbMapKeyJoinColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyJoinColumn) MapKeyJoinColumn(jakarta.persistence.MapKeyJoinColumn) JaxbMapKeyJoinColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyJoinColumn) ArrayList(java.util.ArrayList)

Example 3 with MapKeyJoinColumn

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

the class JPAXMLOverriddenAnnotationReader method getMapKeyJoinColumns.

private void getMapKeyJoinColumns(List<Annotation> annotationList, List<JaxbMapKeyJoinColumn> elements) {
    MapKeyJoinColumn[] joinColumns = buildMapKeyJoinColumns(elements);
    if (joinColumns.length > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(MapKeyJoinColumns.class);
        ad.setValue("value", joinColumns);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbMapKeyJoinColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyJoinColumn) MapKeyJoinColumn(jakarta.persistence.MapKeyJoinColumn)

Example 4 with MapKeyJoinColumn

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

the class Ejb3XmlElementCollectionTest method testSingleMapKeyJoinColumn.

/**
 * When there's a single map key join column, we still wrap it with a
 * MapKeyJoinColumns annotation.
 */
@Test
public void testSingleMapKeyJoinColumn() throws Exception {
    reader = getReader(Entity3.class, "field1", "element-collection.orm14.xml");
    assertAnnotationPresent(ElementCollection.class);
    assertAnnotationNotPresent(MapKey.class);
    assertAnnotationNotPresent(MapKeyClass.class);
    assertAnnotationNotPresent(MapKeyTemporal.class);
    assertAnnotationNotPresent(MapKeyEnumerated.class);
    assertAnnotationNotPresent(MapKeyColumn.class);
    assertAnnotationPresent(MapKeyJoinColumns.class);
    assertAnnotationNotPresent(MapKeyJoinColumn.class);
    MapKeyJoinColumns joinColumnsAnno = reader.getAnnotation(MapKeyJoinColumns.class);
    MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
    assertEquals(1, joinColumns.length);
    assertEquals("col1", joinColumns[0].name());
}
Also used : MapKeyJoinColumn(jakarta.persistence.MapKeyJoinColumn) MapKeyJoinColumns(jakarta.persistence.MapKeyJoinColumns) Test(org.junit.Test)

Example 5 with MapKeyJoinColumn

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

the class Ejb3XmlOneToManyTest method testSingleMapKeyJoinColumn.

/**
 * When there's a single map key join column, we still wrap it with a
 * MapKeyJoinColumns annotation.
 */
@Test
public void testSingleMapKeyJoinColumn() throws Exception {
    reader = getReader(Entity3.class, "field1", "one-to-many.orm14.xml");
    assertAnnotationPresent(OneToMany.class);
    assertAnnotationNotPresent(MapKey.class);
    assertAnnotationNotPresent(MapKeyClass.class);
    assertAnnotationNotPresent(MapKeyTemporal.class);
    assertAnnotationNotPresent(MapKeyEnumerated.class);
    assertAnnotationNotPresent(MapKeyColumn.class);
    assertAnnotationPresent(MapKeyJoinColumns.class);
    assertAnnotationNotPresent(MapKeyJoinColumn.class);
    MapKeyJoinColumns joinColumnsAnno = reader.getAnnotation(MapKeyJoinColumns.class);
    MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
    assertEquals(1, joinColumns.length);
    assertEquals("col1", joinColumns[0].name());
}
Also used : MapKeyJoinColumn(jakarta.persistence.MapKeyJoinColumn) MapKeyJoinColumns(jakarta.persistence.MapKeyJoinColumns) Test(org.junit.Test)

Aggregations

MapKeyJoinColumn (jakarta.persistence.MapKeyJoinColumn)9 MapKeyJoinColumns (jakarta.persistence.MapKeyJoinColumns)7 Test (org.junit.Test)6 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 JaxbMapKeyJoinColumn (org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyJoinColumn)2 Column (jakarta.persistence.Column)1 DiscriminatorColumn (jakarta.persistence.DiscriminatorColumn)1 JoinColumn (jakarta.persistence.JoinColumn)1 MapKeyColumn (jakarta.persistence.MapKeyColumn)1 OrderColumn (jakarta.persistence.OrderColumn)1 PrimaryKeyJoinColumn (jakarta.persistence.PrimaryKeyJoinColumn)1 UniqueConstraint (jakarta.persistence.UniqueConstraint)1 ArrayList (java.util.ArrayList)1 AnnotationException (org.hibernate.AnnotationException)1 AnnotatedDiscriminatorColumn.buildDiscriminatorColumn (org.hibernate.cfg.AnnotatedDiscriminatorColumn.buildDiscriminatorColumn)1 MapKeyColumnDelegator (org.hibernate.cfg.annotations.MapKeyColumnDelegator)1 MapKeyJoinColumnDelegator (org.hibernate.cfg.annotations.MapKeyJoinColumnDelegator)1 Constraint (org.hibernate.mapping.Constraint)1