Search in sources :

Example 1 with EntityListeners

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

the class JPAXMLOverriddenAnnotationReader method getEntityListeners.

private EntityListeners getEntityListeners(ManagedType root, XMLContext.Default defaults) {
    JaxbEntityListeners element = root instanceof EntityOrMappedSuperclass ? ((EntityOrMappedSuperclass) root).getEntityListeners() : null;
    if (element != null) {
        List<Class> entityListenerClasses = new ArrayList<>();
        for (JaxbEntityListener subelement : element.getEntityListener()) {
            String className = subelement.getClazz();
            try {
                entityListenerClasses.add(classLoaderAccess.classForName(XMLContext.buildSafeClassName(className, defaults)));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find class: " + className, e);
            }
        }
        AnnotationDescriptor ad = new AnnotationDescriptor(EntityListeners.class);
        ad.setValue("value", entityListenerClasses.toArray(new Class[entityListenerClasses.size()]));
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(EntityListeners.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) JaxbEntityListeners(org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListeners) JaxbEntityListener(org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListener) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ArrayList(java.util.ArrayList) EntityOrMappedSuperclass(org.hibernate.boot.jaxb.mapping.spi.EntityOrMappedSuperclass) AnnotationException(org.hibernate.AnnotationException) IdClass(jakarta.persistence.IdClass) MapKeyClass(jakarta.persistence.MapKeyClass) JaxbIdClass(org.hibernate.boot.jaxb.mapping.spi.JaxbIdClass) JaxbMapKeyClass(org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyClass) EntityListeners(jakarta.persistence.EntityListeners) JaxbEntityListeners(org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListeners)

Example 2 with EntityListeners

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

the class CallbackDefinitionResolverLegacyImpl method getListeners.

private static void getListeners(XClass currentClazz, List<Class<?>> orderedListeners) {
    EntityListeners entityListeners = currentClazz.getAnnotation(EntityListeners.class);
    if (entityListeners != null) {
        Class<?>[] classes = entityListeners.value();
        int size = classes.length;
        for (int index = size - 1; index >= 0; index--) {
            orderedListeners.add(classes[index]);
        }
    }
    if (useAnnotationAnnotatedByListener) {
        Annotation[] annotations = currentClazz.getAnnotations();
        for (Annotation annot : annotations) {
            entityListeners = annot.getClass().getAnnotation(EntityListeners.class);
            if (entityListeners != null) {
                Class<?>[] classes = entityListeners.value();
                int size = classes.length;
                for (int index = size - 1; index >= 0; index--) {
                    orderedListeners.add(classes[index]);
                }
            }
        }
    }
}
Also used : XClass(org.hibernate.annotations.common.reflection.XClass) EntityListeners(jakarta.persistence.EntityListeners) Annotation(java.lang.annotation.Annotation)

Aggregations

EntityListeners (jakarta.persistence.EntityListeners)2 IdClass (jakarta.persistence.IdClass)1 MapKeyClass (jakarta.persistence.MapKeyClass)1 Annotation (java.lang.annotation.Annotation)1 ArrayList (java.util.ArrayList)1 AnnotationException (org.hibernate.AnnotationException)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 XClass (org.hibernate.annotations.common.reflection.XClass)1 EntityOrMappedSuperclass (org.hibernate.boot.jaxb.mapping.spi.EntityOrMappedSuperclass)1 JaxbEntityListener (org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListener)1 JaxbEntityListeners (org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListeners)1 JaxbIdClass (org.hibernate.boot.jaxb.mapping.spi.JaxbIdClass)1 JaxbMapKeyClass (org.hibernate.boot.jaxb.mapping.spi.JaxbMapKeyClass)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1