Search in sources :

Example 6 with ClassLoadingException

use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.

the class TypeSafeActivator method applyRelationalConstraints.

@SuppressWarnings({ "UnusedDeclaration" })
public static void applyRelationalConstraints(ValidatorFactory factory, Collection<PersistentClass> persistentClasses, Map settings, Dialect dialect, ClassLoaderAccess classLoaderAccess) {
    Class<?>[] groupsArray = GroupsPerOperation.buildGroupsForOperation(GroupsPerOperation.Operation.DDL, settings, classLoaderAccess);
    Set<Class<?>> groups = new HashSet<Class<?>>(Arrays.asList(groupsArray));
    for (PersistentClass persistentClass : persistentClasses) {
        final String className = persistentClass.getClassName();
        if (className == null || className.length() == 0) {
            continue;
        }
        Class<?> clazz;
        try {
            clazz = classLoaderAccess.classForName(className);
        } catch (ClassLoadingException e) {
            throw new AssertionFailure("Entity class not found", e);
        }
        try {
            applyDDL("", persistentClass, clazz, factory, groups, true, dialect);
        } catch (Exception e) {
            LOG.unableToApplyConstraints(className, e);
        }
    }
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) PersistentClass(org.hibernate.mapping.PersistentClass) MappingException(org.hibernate.MappingException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) HashSet(java.util.HashSet) PersistentClass(org.hibernate.mapping.PersistentClass)

Example 7 with ClassLoadingException

use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method checkForOrphanProperties.

private void checkForOrphanProperties(Element tree) {
    Class clazz;
    try {
        clazz = classLoaderAccess.classForName(className);
    } catch (ClassLoadingException e) {
        //a primitive type most likely
        return;
    }
    Element element = tree != null ? tree.element("attributes") : null;
    //put entity.attributes elements
    if (element != null) {
        //precompute the list of properties
        //TODO is it really useful...
        Set<String> properties = new HashSet<String>();
        for (Field field : clazz.getFields()) {
            properties.add(field.getName());
        }
        for (Method method : clazz.getMethods()) {
            String name = method.getName();
            if (name.startsWith("get")) {
                properties.add(Introspector.decapitalize(name.substring("get".length())));
            } else if (name.startsWith("is")) {
                properties.add(Introspector.decapitalize(name.substring("is".length())));
            }
        }
        for (Element subelement : (List<Element>) element.elements()) {
            String propertyName = subelement.attributeValue("name");
            if (!properties.contains(propertyName)) {
                LOG.propertyNotFound(StringHelper.qualify(className, propertyName));
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) MapKeyClass(javax.persistence.MapKeyClass) IdClass(javax.persistence.IdClass) ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method) HashSet(java.util.HashSet)

Example 8 with ClassLoadingException

use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method addTargetClass.

private void addTargetClass(Element element, AnnotationDescriptor ad, String nodeName, XMLContext.Default defaults) {
    String className = element.attributeValue(nodeName);
    if (className != null) {
        Class clazz;
        try {
            clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(className, defaults));
        } catch (ClassLoadingException e) {
            throw new AnnotationException("Unable to find " + element.getPath() + " " + nodeName + ": " + className, e);
        }
        ad.setValue(getJavaAttributeNameFromXMLOne(nodeName), clazz);
    }
}
Also used : ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) AnnotationException(org.hibernate.AnnotationException) MapKeyClass(javax.persistence.MapKeyClass) IdClass(javax.persistence.IdClass)

Example 9 with ClassLoadingException

use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.

the class StandardJtaPlatformResolver method resolveJtaPlatform.

@Override
public JtaPlatform resolveJtaPlatform(Map configurationValues, ServiceRegistryImplementor registry) {
    final ClassLoaderService classLoaderService = registry.getService(ClassLoaderService.class);
    // Initially look for a JtaPlatformProvider
    for (JtaPlatformProvider provider : classLoaderService.loadJavaServices(JtaPlatformProvider.class)) {
        final JtaPlatform providedPlatform = provider.getProvidedJtaPlatform();
        log.tracef("Located JtaPlatformProvider [%s] provided JtaPlaform : %s", provider, providedPlatform);
        if (providedPlatform != null) {
            return providedPlatform;
        }
    }
    // JBoss ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    try {
        classLoaderService.classForName(JBossStandAloneJtaPlatform.JBOSS_TM_CLASS_NAME);
        classLoaderService.classForName(JBossStandAloneJtaPlatform.JBOSS_UT_CLASS_NAME);
        // should be relying on that
        return new JBossStandAloneJtaPlatform();
    } catch (ClassLoadingException ignore) {
    }
    // Bitronix ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    try {
        classLoaderService.classForName(BitronixJtaPlatform.TM_CLASS_NAME);
        return new BitronixJtaPlatform();
    } catch (ClassLoadingException ignore) {
    }
    // JOnAS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    try {
        classLoaderService.classForName(JOnASJtaPlatform.TM_CLASS_NAME);
        return new JOnASJtaPlatform();
    } catch (ClassLoadingException ignore) {
    }
    // JOTM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    try {
        classLoaderService.classForName(JOTMJtaPlatform.TM_CLASS_NAME);
        return new JOTMJtaPlatform();
    } catch (ClassLoadingException ignore) {
    }
    // WebSphere ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    for (WebSphereJtaPlatform.WebSphereEnvironment webSphereEnvironment : WebSphereJtaPlatform.WebSphereEnvironment.values()) {
        try {
            Class accessClass = classLoaderService.classForName(webSphereEnvironment.getTmAccessClassName());
            return new WebSphereJtaPlatform(accessClass, webSphereEnvironment);
        } catch (ClassLoadingException ignore) {
        }
    }
    // Finally, return the default...
    log.debugf("Could not resolve JtaPlatform, using default [%s]", NoJtaPlatform.class.getName());
    return NoJtaPlatform.INSTANCE;
}
Also used : JtaPlatform(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform) JtaPlatformProvider(org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformProvider) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 10 with ClassLoadingException

use of org.hibernate.boot.registry.classloading.spi.ClassLoadingException in project hibernate-orm by hibernate.

the class ConstructorNode method resolveConstructor.

private Constructor resolveConstructor(String path) throws SemanticException {
    String importedClassName = getSessionFactoryHelper().getImportedClassName(path);
    String className = StringHelper.isEmpty(importedClassName) ? path : importedClassName;
    if (className == null) {
        throw new SemanticException("Unable to locate class [" + path + "]");
    }
    try {
        final Class holderClass = getSessionFactoryHelper().getFactory().getServiceRegistry().getService(ClassLoaderService.class).classForName(className);
        return ReflectHelper.getConstructor(holderClass, constructorArgumentTypes);
    } catch (ClassLoadingException e) {
        throw new DetailedSemanticException("Unable to locate class [" + className + "]", e);
    } catch (PropertyNotFoundException e) {
        // locate an appropriate constructor
        throw new DetailedSemanticException(formatMissingContructorExceptionMessage(className), e);
    }
}
Also used : PropertyNotFoundException(org.hibernate.PropertyNotFoundException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) DetailedSemanticException(org.hibernate.hql.internal.ast.DetailedSemanticException) SemanticException(antlr.SemanticException) DetailedSemanticException(org.hibernate.hql.internal.ast.DetailedSemanticException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Aggregations

ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)26 Element (org.dom4j.Element)10 AnnotationException (org.hibernate.AnnotationException)10 AnnotatedElement (java.lang.reflect.AnnotatedElement)9 IdClass (javax.persistence.IdClass)9 MapKeyClass (javax.persistence.MapKeyClass)9 ArrayList (java.util.ArrayList)8 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)7 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)7 List (java.util.List)5 MappingException (org.hibernate.MappingException)5 HibernateException (org.hibernate.HibernateException)3 AccessibleObject (java.lang.reflect.AccessibleObject)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 NamedNativeQuery (javax.persistence.NamedNativeQuery)2 NamedQuery (javax.persistence.NamedQuery)2 NamedStoredProcedureQuery (javax.persistence.NamedStoredProcedureQuery)2 Attribute (org.dom4j.Attribute)2