Search in sources :

Example 1 with JaxbEmbedded

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

the class JPAXMLOverriddenAnnotationReader method getConvertsForAttribute.

private Annotation getConvertsForAttribute(PropertyMappingElementCollector elementsForProperty, XMLContext.Default defaults) {
    // NOTE : we use a map here to make sure that an xml and annotation referring to the same attribute
    // properly overrides.  Very sparse map, yes, but easy setup.
    // todo : revisit this
    // although bear in mind that this code is no longer used in 5.0...
    final Map<String, Convert> convertAnnotationsMap = new HashMap<>();
    for (JaxbBasic element : elementsForProperty.getBasic()) {
        JaxbConvert convert = element.getConvert();
        if (convert != null) {
            applyXmlDefinedConverts(Collections.singletonList(convert), defaults, null, convertAnnotationsMap);
        }
    }
    for (JaxbEmbedded element : elementsForProperty.getEmbedded()) {
        applyXmlDefinedConverts(element.getConvert(), defaults, propertyName, convertAnnotationsMap);
    }
    for (JaxbElementCollection element : elementsForProperty.getElementCollection()) {
        applyXmlDefinedConverts(element.getConvert(), defaults, propertyName, convertAnnotationsMap);
    }
    if (defaults.canUseJavaAnnotations()) {
        // todo : note sure how to best handle attributeNamePrefix here
        applyPhysicalConvertAnnotations(propertyName, convertAnnotationsMap);
    }
    if (!convertAnnotationsMap.isEmpty()) {
        final AnnotationDescriptor groupingDescriptor = new AnnotationDescriptor(Converts.class);
        groupingDescriptor.setValue("value", convertAnnotationsMap.values().toArray(new Convert[convertAnnotationsMap.size()]));
        return AnnotationFactory.create(groupingDescriptor);
    }
    return null;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Convert(jakarta.persistence.Convert) JaxbConvert(org.hibernate.boot.jaxb.mapping.spi.JaxbConvert) HashMap(java.util.HashMap) JaxbConvert(org.hibernate.boot.jaxb.mapping.spi.JaxbConvert) JaxbEmbedded(org.hibernate.boot.jaxb.mapping.spi.JaxbEmbedded) JaxbElementCollection(org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollection) JaxbBasic(org.hibernate.boot.jaxb.mapping.spi.JaxbBasic)

Example 2 with JaxbEmbedded

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

the class JPAXMLOverriddenAnnotationReader method getEmbedded.

private void getEmbedded(List<Annotation> annotationList, XMLContext.Default defaults) {
    for (JaxbEmbedded element : elementsForProperty.getEmbedded()) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Embedded.class);
        annotationList.add(AnnotationFactory.create(ad));
        Annotation annotation = getAttributeOverrides(element.getAttributeOverride(), defaults, false);
        addIfNotNull(annotationList, annotation);
        annotation = getAssociationOverrides(element.getAssociationOverride(), defaults, false);
        addIfNotNull(annotationList, annotation);
        getAccessType(annotationList, element.getAccess());
    }
    if (elementsForProperty.isEmpty() && defaults.canUseJavaAnnotations()) {
        Annotation annotation = getPhysicalAnnotation(Embedded.class);
        if (annotation != null) {
            annotationList.add(annotation);
            annotation = getPhysicalAnnotation(AttributeOverride.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(AttributeOverrides.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(AssociationOverride.class);
            addIfNotNull(annotationList, annotation);
            annotation = getPhysicalAnnotation(AssociationOverrides.class);
            addIfNotNull(annotationList, annotation);
        }
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AttributeOverrides(jakarta.persistence.AttributeOverrides) AssociationOverrides(jakarta.persistence.AssociationOverrides) AssociationOverride(jakarta.persistence.AssociationOverride) JaxbAssociationOverride(org.hibernate.boot.jaxb.mapping.spi.JaxbAssociationOverride) JaxbEmbedded(org.hibernate.boot.jaxb.mapping.spi.JaxbEmbedded) Annotation(java.lang.annotation.Annotation) JaxbAttributeOverride(org.hibernate.boot.jaxb.mapping.spi.JaxbAttributeOverride) AttributeOverride(jakarta.persistence.AttributeOverride)

Aggregations

AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 JaxbEmbedded (org.hibernate.boot.jaxb.mapping.spi.JaxbEmbedded)2 AssociationOverride (jakarta.persistence.AssociationOverride)1 AssociationOverrides (jakarta.persistence.AssociationOverrides)1 AttributeOverride (jakarta.persistence.AttributeOverride)1 AttributeOverrides (jakarta.persistence.AttributeOverrides)1 Convert (jakarta.persistence.Convert)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 JaxbAssociationOverride (org.hibernate.boot.jaxb.mapping.spi.JaxbAssociationOverride)1 JaxbAttributeOverride (org.hibernate.boot.jaxb.mapping.spi.JaxbAttributeOverride)1 JaxbBasic (org.hibernate.boot.jaxb.mapping.spi.JaxbBasic)1 JaxbConvert (org.hibernate.boot.jaxb.mapping.spi.JaxbConvert)1 JaxbElementCollection (org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollection)1