Search in sources :

Example 6 with Access

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

the class PropertyContainer method collectPersistentAttributesUsingLocalAccessType.

private static void collectPersistentAttributesUsingLocalAccessType(XClass xClass, TreeMap<String, XProperty> persistentAttributeMap, Map<String, XProperty> persistentAttributesFromGetters, List<XProperty> fields, List<XProperty> getters) {
    // Check fields...
    Iterator<XProperty> propertyIterator = fields.iterator();
    while (propertyIterator.hasNext()) {
        final XProperty xProperty = propertyIterator.next();
        final Access localAccessAnnotation = xProperty.getAnnotation(Access.class);
        if (localAccessAnnotation == null || localAccessAnnotation.value() != jakarta.persistence.AccessType.FIELD) {
            continue;
        }
        propertyIterator.remove();
        persistentAttributeMap.put(xProperty.getName(), xProperty);
    }
    // Check getters...
    propertyIterator = getters.iterator();
    while (propertyIterator.hasNext()) {
        final XProperty xProperty = propertyIterator.next();
        final Access localAccessAnnotation = xProperty.getAnnotation(Access.class);
        if (localAccessAnnotation == null || localAccessAnnotation.value() != jakarta.persistence.AccessType.PROPERTY) {
            continue;
        }
        propertyIterator.remove();
        final String name = xProperty.getName();
        // HHH-10242 detect registration of the same property getter twice - eg boolean isId() + UUID getId()
        final XProperty previous = persistentAttributesFromGetters.get(name);
        if (previous != null) {
            throw new org.hibernate.boot.MappingException(LOG.ambiguousPropertyMethods(xClass.getName(), HCANNHelper.annotatedElementSignature(previous), HCANNHelper.annotatedElementSignature(xProperty)), new Origin(SourceType.ANNOTATION, xClass.getName()));
        }
        persistentAttributeMap.put(name, xProperty);
        persistentAttributesFromGetters.put(name, xProperty);
    }
}
Also used : Origin(org.hibernate.boot.jaxb.Origin) XProperty(org.hibernate.annotations.common.reflection.XProperty) Access(jakarta.persistence.Access)

Aggregations

Access (jakarta.persistence.Access)6 XProperty (org.hibernate.annotations.common.reflection.XProperty)2 AccessType (org.hibernate.cfg.AccessType)2 AccessType (jakarta.persistence.AccessType)1 AttributeOverride (jakarta.persistence.AttributeOverride)1 AttributeOverrides (jakarta.persistence.AttributeOverrides)1 AssertionFailure (org.hibernate.AssertionFailure)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 XClass (org.hibernate.annotations.common.reflection.XClass)1 Origin (org.hibernate.boot.jaxb.Origin)1 ClassLoaderAccess (org.hibernate.boot.spi.ClassLoaderAccess)1 AnnotatedClassType (org.hibernate.cfg.AnnotatedClassType)1 AnnotatedColumn (org.hibernate.cfg.AnnotatedColumn)1 AnnotationBinder.fillComponent (org.hibernate.cfg.AnnotationBinder.fillComponent)1 CollectionPropertyHolder (org.hibernate.cfg.CollectionPropertyHolder)1 Component (org.hibernate.mapping.Component)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 Property (org.hibernate.mapping.Property)1