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);
}
}
}
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);
}
}
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);
}
}
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");
}
}
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);
}
}
Aggregations