Search in sources :

Example 1 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 2 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 3 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)

Example 4 with ClassLoadingException

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

the class UUIDGenerator method configure.

@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
    // check first for the strategy instance
    strategy = (UUIDGenerationStrategy) params.get(UUID_GEN_STRATEGY);
    if (strategy == null) {
        // next check for the strategy class
        final String strategyClassName = params.getProperty(UUID_GEN_STRATEGY_CLASS);
        if (strategyClassName != null) {
            try {
                final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
                final Class strategyClass = cls.classForName(strategyClassName);
                try {
                    strategy = (UUIDGenerationStrategy) strategyClass.newInstance();
                } catch (Exception ignore) {
                    LOG.unableToInstantiateUuidGenerationStrategy(ignore);
                }
            } catch (ClassLoadingException ignore) {
                LOG.unableToLocateUuidGenerationStrategy(strategyClassName);
            }
        }
    }
    if (strategy == null) {
        // lastly use the standard random generator
        strategy = StandardRandomStrategy.INSTANCE;
    }
    if (UUID.class.isAssignableFrom(type.getReturnedClass())) {
        valueTransformer = UUIDTypeDescriptor.PassThroughTransformer.INSTANCE;
    } else if (String.class.isAssignableFrom(type.getReturnedClass())) {
        valueTransformer = UUIDTypeDescriptor.ToStringTransformer.INSTANCE;
    } else if (byte[].class.isAssignableFrom(type.getReturnedClass())) {
        valueTransformer = UUIDTypeDescriptor.ToBytesTransformer.INSTANCE;
    } else {
        throw new HibernateException("Unanticipated return type [" + type.getReturnedClass().getName() + "] for UUID conversion");
    }
}
Also used : HibernateException(org.hibernate.HibernateException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) MappingException(org.hibernate.MappingException) HibernateException(org.hibernate.HibernateException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService)

Example 5 with ClassLoadingException

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

the class AbstractSharedSessionContract method resultClassChecking.

@SuppressWarnings({ "unchecked", "WeakerAccess" })
protected void resultClassChecking(Class resultType, NamedSQLQueryDefinition namedQueryDefinition) {
    final NativeSQLQueryReturn[] queryReturns;
    if (namedQueryDefinition.getQueryReturns() != null) {
        queryReturns = namedQueryDefinition.getQueryReturns();
    } else if (namedQueryDefinition.getResultSetRef() != null) {
        final ResultSetMappingDefinition rsMapping = getFactory().getNamedQueryRepository().getResultSetMappingDefinition(namedQueryDefinition.getResultSetRef());
        queryReturns = rsMapping.getQueryReturns();
    } else {
        throw new AssertionFailure("Unsupported named query model. Please report the bug in Hibernate EntityManager");
    }
    if (queryReturns.length > 1) {
        throw new IllegalArgumentException("Cannot create TypedQuery for query with more than one return");
    }
    final NativeSQLQueryReturn nativeSQLQueryReturn = queryReturns[0];
    if (nativeSQLQueryReturn instanceof NativeSQLQueryRootReturn) {
        final Class<?> actualReturnedClass;
        final String entityClassName = ((NativeSQLQueryRootReturn) nativeSQLQueryReturn).getReturnEntityName();
        try {
            actualReturnedClass = getFactory().getServiceRegistry().getService(ClassLoaderService.class).classForName(entityClassName);
        } catch (ClassLoadingException e) {
            throw new AssertionFailure("Unable to load class [" + entityClassName + "] declared on named native query [" + namedQueryDefinition.getName() + "]");
        }
        if (!resultType.isAssignableFrom(actualReturnedClass)) {
            throw buildIncompatibleException(resultType, actualReturnedClass);
        }
    } else if (nativeSQLQueryReturn instanceof NativeSQLQueryConstructorReturn) {
        final NativeSQLQueryConstructorReturn ctorRtn = (NativeSQLQueryConstructorReturn) nativeSQLQueryReturn;
        if (!resultType.isAssignableFrom(ctorRtn.getTargetClass())) {
            throw buildIncompatibleException(resultType, ctorRtn.getTargetClass());
        }
    } else {
        log.debugf("Skiping unhandled NativeSQLQueryReturn type : " + nativeSQLQueryReturn);
    }
}
Also used : AssertionFailure(org.hibernate.AssertionFailure) NativeSQLQueryConstructorReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryConstructorReturn) NativeSQLQueryReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) NativeSQLQueryRootReturn(org.hibernate.engine.query.spi.sql.NativeSQLQueryRootReturn) ResultSetMappingDefinition(org.hibernate.engine.ResultSetMappingDefinition)

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