Search in sources :

Example 1 with JaxbPrimaryKeyJoinColumn

use of org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumn in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method getPrimaryKeyJoinColumns.

/**
 * @param mergeWithAnnotations Whether to use Java annotations for this
 * element, if present and not disabled by the XMLContext defaults.
 * In some contexts (such as an association mapping) merging with
 */
private PrimaryKeyJoinColumns getPrimaryKeyJoinColumns(List<JaxbPrimaryKeyJoinColumn> elements, XMLContext.Default defaults, boolean mergeWithAnnotations) {
    PrimaryKeyJoinColumn[] columns = buildPrimaryKeyJoinColumns(elements);
    if (mergeWithAnnotations) {
        if (columns.length == 0 && defaults.canUseJavaAnnotations()) {
            PrimaryKeyJoinColumn annotation = getPhysicalAnnotation(PrimaryKeyJoinColumn.class);
            if (annotation != null) {
                columns = new PrimaryKeyJoinColumn[] { annotation };
            } else {
                PrimaryKeyJoinColumns annotations = getPhysicalAnnotation(PrimaryKeyJoinColumns.class);
                columns = annotations != null ? annotations.value() : columns;
            }
        }
    }
    if (columns.length > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(PrimaryKeyJoinColumns.class);
        ad.setValue("value", columns);
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbPrimaryKeyJoinColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumn) PrimaryKeyJoinColumn(jakarta.persistence.PrimaryKeyJoinColumn) PrimaryKeyJoinColumns(jakarta.persistence.PrimaryKeyJoinColumns)

Example 2 with JaxbPrimaryKeyJoinColumn

use of org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumn in project hibernate-orm by hibernate.

the class JPAXMLOverriddenAnnotationReader method buildPrimaryKeyJoinColumns.

private PrimaryKeyJoinColumn[] buildPrimaryKeyJoinColumns(List<JaxbPrimaryKeyJoinColumn> elements) {
    PrimaryKeyJoinColumn[] pkJoinColumns = new PrimaryKeyJoinColumn[elements.size()];
    int i = 0;
    for (JaxbPrimaryKeyJoinColumn element : elements) {
        AnnotationDescriptor pkAnn = new AnnotationDescriptor(PrimaryKeyJoinColumn.class);
        copyAttribute(pkAnn, "name", element.getName(), false);
        copyAttribute(pkAnn, "referenced-column-name", element.getReferencedColumnName(), false);
        copyAttribute(pkAnn, "column-definition", element.getColumnDefinition(), false);
        pkJoinColumns[i++] = AnnotationFactory.create(pkAnn);
    }
    return pkJoinColumns;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbPrimaryKeyJoinColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumn) PrimaryKeyJoinColumn(jakarta.persistence.PrimaryKeyJoinColumn) JaxbPrimaryKeyJoinColumn(org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumn) JaxbUniqueConstraint(org.hibernate.boot.jaxb.mapping.spi.JaxbUniqueConstraint) QueryHint(jakarta.persistence.QueryHint) JaxbQueryHint(org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHint) UniqueConstraint(jakarta.persistence.UniqueConstraint)

Aggregations

PrimaryKeyJoinColumn (jakarta.persistence.PrimaryKeyJoinColumn)2 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 JaxbPrimaryKeyJoinColumn (org.hibernate.boot.jaxb.mapping.spi.JaxbPrimaryKeyJoinColumn)2 PrimaryKeyJoinColumns (jakarta.persistence.PrimaryKeyJoinColumns)1 QueryHint (jakarta.persistence.QueryHint)1 UniqueConstraint (jakarta.persistence.UniqueConstraint)1 JaxbQueryHint (org.hibernate.boot.jaxb.mapping.spi.JaxbQueryHint)1 JaxbUniqueConstraint (org.hibernate.boot.jaxb.mapping.spi.JaxbUniqueConstraint)1