Search in sources :

Example 6 with PropertyNotFoundException

use of org.hibernate.PropertyNotFoundException in project hibernate-orm by hibernate.

the class ReflectHelper method findGetterMethod.

public static Method findGetterMethod(Class containerClass, String propertyName) {
    Class checkClass = containerClass;
    Method getter = null;
    // check containerClass, and then its super types (if any)
    while (getter == null && checkClass != null) {
        if (checkClass.equals(Object.class)) {
            break;
        }
        getter = getGetterOrNull(checkClass, propertyName);
        checkClass = checkClass.getSuperclass();
    }
    // if no getter found yet, check all implemented interfaces
    if (getter == null) {
        getter = getGetterOrNull(containerClass.getInterfaces(), propertyName);
    }
    if (getter == null) {
        throw new PropertyNotFoundException(String.format(Locale.ROOT, "Could not locate getter method for property [%s#%s]", containerClass.getName(), propertyName));
    }
    getter.setAccessible(true);
    return getter;
}
Also used : PropertyNotFoundException(org.hibernate.PropertyNotFoundException) Method(java.lang.reflect.Method)

Example 7 with PropertyNotFoundException

use of org.hibernate.PropertyNotFoundException in project hibernate-orm by hibernate.

the class ReflectHelper method findSetterMethod.

public static Method findSetterMethod(Class containerClass, String propertyName, Class propertyType) {
    Class checkClass = containerClass;
    Method setter = null;
    // check containerClass, and then its super types (if any)
    while (setter == null && checkClass != null) {
        if (checkClass.equals(Object.class)) {
            break;
        }
        setter = setterOrNull(checkClass, propertyName, propertyType);
        checkClass = checkClass.getSuperclass();
    }
    // if no setter found yet, check all implemented interfaces
    if (setter == null) {
        setter = setterOrNull(containerClass.getInterfaces(), propertyName, propertyType);
    //			for ( Class theInterface : containerClass.getInterfaces() ) {
    //				setter = setterOrNull( theInterface, propertyName, propertyType );
    //				if ( setter != null ) {
    //					break;
    //				}
    //			}
    }
    if (setter == null) {
        throw new PropertyNotFoundException(String.format(Locale.ROOT, "Could not locate setter method for property [%s#%s]", containerClass.getName(), propertyName));
    }
    setter.setAccessible(true);
    return setter;
}
Also used : PropertyNotFoundException(org.hibernate.PropertyNotFoundException) Method(java.lang.reflect.Method)

Aggregations

PropertyNotFoundException (org.hibernate.PropertyNotFoundException)7 Method (java.lang.reflect.Method)2 SemanticException (antlr.SemanticException)1 Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 FlushModeType (javax.persistence.FlushModeType)1 LockModeType (javax.persistence.LockModeType)1 TemporalType (javax.persistence.TemporalType)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1 DetailedSemanticException (org.hibernate.hql.internal.ast.DetailedSemanticException)1 Getter (org.hibernate.property.access.spi.Getter)1 PropertyAccess (org.hibernate.property.access.spi.PropertyAccess)1 PrimitiveType (org.hibernate.type.PrimitiveType)1 Type (org.hibernate.type.Type)1