Search in sources :

Example 1 with JaxbElementCollection

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

the class JPAXMLOverriddenAnnotationReader method getElementCollection.

/**
 * As per sections 12.2.3.23.9, 12.2.4.8.9 and 12.2.5.3.6 of the JPA 2.0
 * specification, the element-collection subelement completely overrides the
 * mapping for the specified field or property.  Thus, any methods which
 * might in some contexts merge with annotations must not do so in this
 * context.
 */
private void getElementCollection(List<Annotation> annotationList, XMLContext.Default defaults) {
    for (JaxbElementCollection element : elementsForProperty.getElementCollection()) {
        AnnotationDescriptor ad = new AnnotationDescriptor(ElementCollection.class);
        addTargetClass(element.getTargetClass(), ad, "target-class", defaults);
        getFetchType(ad, element.getFetch());
        getOrderBy(annotationList, element.getOrderBy());
        getOrderColumn(annotationList, element.getOrderColumn());
        getMapKey(annotationList, element.getMapKey());
        getMapKeyClass(annotationList, element.getMapKeyClass(), defaults);
        getMapKeyTemporal(annotationList, element.getMapKeyTemporal());
        getMapKeyEnumerated(annotationList, element.getMapKeyEnumerated());
        getMapKeyColumn(annotationList, element.getMapKeyColumn());
        getMapKeyJoinColumns(annotationList, element.getMapKeyJoinColumn());
        Annotation annotation = getColumn(element.getColumn(), false, "element-collection");
        addIfNotNull(annotationList, annotation);
        getTemporal(annotationList, element.getTemporal());
        getEnumerated(annotationList, element.getEnumerated());
        getLob(annotationList, element.getLob());
        // Both map-key-attribute-overrides and attribute-overrides
        // translate into AttributeOverride annotations, which need
        // need to be wrapped in the same AttributeOverrides annotation.
        List<AttributeOverride> attributes = new ArrayList<>();
        attributes.addAll(buildAttributeOverrides(element.getMapKeyAttributeOverride(), "map-key-attribute-override"));
        attributes.addAll(buildAttributeOverrides(element.getAttributeOverride(), "attribute-override"));
        annotation = mergeAttributeOverrides(defaults, attributes, false);
        addIfNotNull(annotationList, annotation);
        annotation = getAssociationOverrides(element.getAssociationOverride(), defaults, false);
        addIfNotNull(annotationList, annotation);
        getCollectionTable(annotationList, element.getCollectionTable(), defaults);
        annotationList.add(AnnotationFactory.create(ad));
        getAccessType(annotationList, element.getAccess());
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) ArrayList(java.util.ArrayList) JaxbElementCollection(org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollection) Annotation(java.lang.annotation.Annotation) JaxbAttributeOverride(org.hibernate.boot.jaxb.mapping.spi.JaxbAttributeOverride) AttributeOverride(jakarta.persistence.AttributeOverride)

Example 2 with JaxbElementCollection

use of org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollection 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)

Aggregations

AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 JaxbElementCollection (org.hibernate.boot.jaxb.mapping.spi.JaxbElementCollection)2 AttributeOverride (jakarta.persistence.AttributeOverride)1 Convert (jakarta.persistence.Convert)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)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 JaxbEmbedded (org.hibernate.boot.jaxb.mapping.spi.JaxbEmbedded)1