Search in sources :

Example 1 with JaxbAssociationOverride

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

the class JPAXMLOverriddenAnnotationReader method getAssociationOverrides.

/**
 * @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 element-collection mapping) merging
 */
private AssociationOverrides getAssociationOverrides(List<JaxbAssociationOverride> elements, XMLContext.Default defaults, boolean mergeWithAnnotations) {
    List<AssociationOverride> attributes = buildAssociationOverrides(elements, defaults);
    if (mergeWithAnnotations && defaults.canUseJavaAnnotations()) {
        AssociationOverride annotation = getPhysicalAnnotation(AssociationOverride.class);
        addAssociationOverrideIfNeeded(annotation, attributes);
        AssociationOverrides annotations = getPhysicalAnnotation(AssociationOverrides.class);
        if (annotations != null) {
            for (AssociationOverride current : annotations.value()) {
                addAssociationOverrideIfNeeded(current, attributes);
            }
        }
    }
    if (attributes.size() > 0) {
        AnnotationDescriptor ad = new AnnotationDescriptor(AssociationOverrides.class);
        ad.setValue("value", attributes.toArray(new AssociationOverride[attributes.size()]));
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AssociationOverrides(jakarta.persistence.AssociationOverrides) AssociationOverride(jakarta.persistence.AssociationOverride) JaxbAssociationOverride(org.hibernate.boot.jaxb.mapping.spi.JaxbAssociationOverride)

Example 2 with JaxbAssociationOverride

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

the class JPAXMLOverriddenAnnotationReader method buildAssociationOverrides.

private List<AssociationOverride> buildAssociationOverrides(List<JaxbAssociationOverride> elements, XMLContext.Default defaults) {
    List<AssociationOverride> overrides = new ArrayList<>();
    if (elements != null && elements.size() > 0) {
        for (JaxbAssociationOverride current : elements) {
            AnnotationDescriptor override = new AnnotationDescriptor(AssociationOverride.class);
            copyAttribute(override, "name", current.getName(), true);
            override.setValue("joinColumns", getJoinColumns(current.getJoinColumn(), false));
            JoinTable joinTable = buildJoinTable(current.getJoinTable(), defaults);
            if (joinTable != null) {
                override.setValue("joinTable", joinTable);
            }
            overrides.add(AnnotationFactory.create(override));
        }
    }
    return overrides;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AssociationOverride(jakarta.persistence.AssociationOverride) JaxbAssociationOverride(org.hibernate.boot.jaxb.mapping.spi.JaxbAssociationOverride) ArrayList(java.util.ArrayList) JaxbAssociationOverride(org.hibernate.boot.jaxb.mapping.spi.JaxbAssociationOverride) JaxbJoinTable(org.hibernate.boot.jaxb.mapping.spi.JaxbJoinTable) JoinTable(jakarta.persistence.JoinTable)

Aggregations

AssociationOverride (jakarta.persistence.AssociationOverride)2 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 JaxbAssociationOverride (org.hibernate.boot.jaxb.mapping.spi.JaxbAssociationOverride)2 AssociationOverrides (jakarta.persistence.AssociationOverrides)1 JoinTable (jakarta.persistence.JoinTable)1 ArrayList (java.util.ArrayList)1 JaxbJoinTable (org.hibernate.boot.jaxb.mapping.spi.JaxbJoinTable)1