Search in sources :

Example 1 with EntityOrMappedSuperclass

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

the class JPAXMLOverriddenAnnotationReader method getIdClass.

private IdClass getIdClass(ManagedType root, XMLContext.Default defaults) {
    JaxbIdClass element = root instanceof EntityOrMappedSuperclass ? ((EntityOrMappedSuperclass) root).getIdClass() : null;
    if (element != null) {
        String className = element.getClazz();
        if (className != null) {
            AnnotationDescriptor ad = new AnnotationDescriptor(IdClass.class);
            Class<?> clazz;
            try {
                clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(className, defaults));
            } catch (ClassLoadingException e) {
                throw new AnnotationException("Unable to find id-class: " + className, e);
            }
            ad.setValue("value", clazz);
            return AnnotationFactory.create(ad);
        } else {
            throw new AnnotationException("id-class without class. " + SCHEMA_VALIDATION);
        }
    } else if (defaults.canUseJavaAnnotations()) {
        return getPhysicalAnnotation(IdClass.class);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) IdClass(jakarta.persistence.IdClass) JaxbIdClass(org.hibernate.boot.jaxb.mapping.spi.JaxbIdClass) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) JaxbIdClass(org.hibernate.boot.jaxb.mapping.spi.JaxbIdClass) EntityOrMappedSuperclass(org.hibernate.boot.jaxb.mapping.spi.EntityOrMappedSuperclass) AnnotationException(org.hibernate.AnnotationException)

Example 2 with EntityOrMappedSuperclass

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

Aggregations

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