org.hibernate.PropertyNotFoundException Java Examples
The following examples show how to use
org.hibernate.PropertyNotFoundException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractQueryImpl.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public Query setProperties(Object bean) throws HibernateException { Class clazz = bean.getClass(); String[] params = getNamedParameters(); for (int i = 0; i < params.length; i++) { String namedParam = params[i]; try { Getter getter = ReflectHelper.getGetter( clazz, namedParam ); Class retType = getter.getReturnType(); final Object object = getter.get( bean ); if ( Collection.class.isAssignableFrom( retType ) ) { setParameterList( namedParam, ( Collection ) object ); } else if ( retType.isArray() ) { setParameterList( namedParam, ( Object[] ) object ); } else { setParameter( namedParam, object, determineType( namedParam, retType ) ); } } catch (PropertyNotFoundException pnfe) { // ignore } } return this; }
Example #2
Source File: ReflectHelper.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public static Constructor getConstructor(Class clazz, Type[] types) throws PropertyNotFoundException { final Constructor[] candidates = clazz.getConstructors(); for ( int i=0; i<candidates.length; i++ ) { final Constructor constructor = candidates[i]; final Class[] params = constructor.getParameterTypes(); if ( params.length==types.length ) { boolean found = true; for ( int j=0; j<params.length; j++ ) { final boolean ok = params[j].isAssignableFrom( types[j].getReturnedClass() ) || ( types[j] instanceof PrimitiveType && params[j] == ( (PrimitiveType) types[j] ).getPrimitiveClass() ); if (!ok) { found = false; break; } } if (found) { if ( !isPublic(clazz, constructor) ) constructor.setAccessible(true); return constructor; } } } throw new PropertyNotFoundException( "no appropriate constructor in class: " + clazz.getName() ); }
Example #3
Source File: ReflectHelper.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public static Constructor getDefaultConstructor(Class clazz) throws PropertyNotFoundException { if ( isAbstractClass(clazz) ) return null; try { Constructor constructor = clazz.getDeclaredConstructor(NO_CLASSES); if ( !isPublic(clazz, constructor) ) { constructor.setAccessible(true); } return constructor; } catch (NoSuchMethodException nme) { throw new PropertyNotFoundException( "Object class " + clazz.getName() + " must declare a default (no-argument) constructor" ); } }
Example #4
Source File: PojoInstantiator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public PojoInstantiator(PersistentClass persistentClass, ReflectionOptimizer.InstantiationOptimizer optimizer) { this.mappedClass = persistentClass.getMappedClass(); this.proxyInterface = persistentClass.getProxyInterface(); this.embeddedIdentifier = persistentClass.hasEmbeddedIdentifier(); this.optimizer = optimizer; try { constructor = ReflectHelper.getDefaultConstructor( mappedClass ); } catch ( PropertyNotFoundException pnfe ) { log.info( "no default (no-argument) constructor for class: " + mappedClass.getName() + " (class must be instantiated by Interceptor)" ); constructor = null; } }
Example #5
Source File: PojoInstantiator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public PojoInstantiator(Component component, ReflectionOptimizer.InstantiationOptimizer optimizer) { this.mappedClass = component.getComponentClass(); this.optimizer = optimizer; this.proxyInterface = null; this.embeddedIdentifier = false; try { constructor = ReflectHelper.getDefaultConstructor(mappedClass); } catch ( PropertyNotFoundException pnfe ) { log.info( "no default (no-argument) constructor for class: " + mappedClass.getName() + " (class must be instantiated by Interceptor)" ); constructor = null; } }
Example #6
Source File: Dom4jAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * Create a "setter" for the named attribute */ public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException { if (nodeName==null) { throw new MappingException("no node name for property: " + propertyName); } if ( ".".equals(nodeName) ) { return new TextSetter(propertyType); } else if ( nodeName.indexOf('/')>-1 ) { return new ElementAttributeSetter(nodeName, propertyType); } else if ( nodeName.indexOf('@')>-1 ) { return new AttributeSetter(nodeName, propertyType); } else { return new ElementSetter(nodeName, propertyType); } }
Example #7
Source File: ReflectHelper.java From lams with GNU General Public License v2.0 | 6 votes |
public static Field findField(Class containerClass, String propertyName) { if ( containerClass == null ) { throw new IllegalArgumentException( "Class on which to find field [" + propertyName + "] cannot be null" ); } else if ( containerClass == Object.class ) { throw new IllegalArgumentException( "Illegal attempt to locate field [" + propertyName + "] on Object.class" ); } Field field = locateField( containerClass, propertyName ); if ( field == null ) { throw new PropertyNotFoundException( String.format( Locale.ROOT, "Could not locate field name [%s] on class [%s]", propertyName, containerClass.getName() ) ); } ensureAccessibility( field ); return field; }
Example #8
Source File: ReflectHelper.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Retrieve the default (no arg) constructor from the given class. * * @param clazz The class for which to retrieve the default ctor. * @return The default constructor. * @throws PropertyNotFoundException Indicates there was not publicly accessible, no-arg constructor (todo : why PropertyNotFoundException???) */ public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz) throws PropertyNotFoundException { if ( isAbstractClass( clazz ) ) { return null; } try { Constructor<T> constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE ); ensureAccessibility( constructor ); return constructor; } catch ( NoSuchMethodException nme ) { throw new PropertyNotFoundException( "Object class [" + clazz.getName() + "] must declare a default (no-argument) constructor" ); } }
Example #9
Source File: Dom4jAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * Create a "getter" for the named attribute */ public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException { if (nodeName==null) { throw new MappingException("no node name for property: " + propertyName); } if ( ".".equals(nodeName) ) { return new TextGetter(propertyType, factory); } else if ( nodeName.indexOf('/')>-1 ) { return new ElementAttributeGetter(nodeName, propertyType, factory); } else if ( nodeName.indexOf('@')>-1 ) { return new AttributeGetter(nodeName, propertyType, factory); } else { return new ElementGetter(nodeName, propertyType, factory); } }
Example #10
Source File: PojoInstantiator.java From lams with GNU General Public License v2.0 | 6 votes |
public PojoInstantiator( Class mappedClass, ReflectionOptimizer.InstantiationOptimizer optimizer, boolean embeddedIdentifier) { this.mappedClass = mappedClass; this.optimizer = optimizer; this.embeddedIdentifier = embeddedIdentifier; this.isAbstract = ReflectHelper.isAbstractClass( mappedClass ); try { constructor = ReflectHelper.getDefaultConstructor(mappedClass); } catch ( PropertyNotFoundException pnfe ) { LOG.noDefaultConstructor( mappedClass.getName() ); constructor = null; } }
Example #11
Source File: BasicPropertyAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public static Getter createGetter(Class theClass, String propertyName) throws PropertyNotFoundException { BasicGetter result = getGetterOrNull(theClass, propertyName); if (result==null) { throw new PropertyNotFoundException( "Could not find a getter for " + propertyName + " in class " + theClass.getName() ); } return result; }
Example #12
Source File: BasicPropertyAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Setter createSetter(Class theClass, String propertyName) throws PropertyNotFoundException { BasicSetter result = getSetterOrNull(theClass, propertyName); if (result==null) { throw new PropertyNotFoundException( "Could not find a setter for property " + propertyName + " in class " + theClass.getName() ); } return result; }
Example #13
Source File: DirectPropertyAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Field getField(Class clazz, String name) throws PropertyNotFoundException { if ( clazz==null || clazz==Object.class ) { throw new PropertyNotFoundException("field not found: " + name); } Field field; try { field = clazz.getDeclaredField(name); } catch (NoSuchFieldException nsfe) { field = getField( clazz, clazz.getSuperclass(), name ); } if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true); return field; }
Example #14
Source File: DirectPropertyAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Field getField(Class root, Class clazz, String name) throws PropertyNotFoundException { if ( clazz==null || clazz==Object.class ) { throw new PropertyNotFoundException("field [" + name + "] not found on " + root.getName()); } Field field; try { field = clazz.getDeclaredField(name); } catch (NoSuchFieldException nsfe) { field = getField( root, clazz.getSuperclass(), name ); } if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true); return field; }
Example #15
Source File: ReflectHelper.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Getter getter(Class clazz, String name) throws MappingException { try { return BASIC_PROPERTY_ACCESSOR.getGetter(clazz, name); } catch (PropertyNotFoundException pnfe) { return DIRECT_PROPERTY_ACCESSOR.getGetter(clazz, name); } }
Example #16
Source File: ChainedPropertyAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException { Setter result = null; for (int i = 0; i < chain.length; i++) { PropertyAccessor candidate = chain[i]; try { result = candidate.getSetter(theClass, propertyName); return result; } catch (PropertyNotFoundException pnfe) { // } } throw new PropertyNotFoundException("Could not find setter for " + propertyName + " on " + theClass); }
Example #17
Source File: ChainedPropertyAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException { Getter result = null; for (int i = 0; i < chain.length; i++) { PropertyAccessor candidate = chain[i]; try { result = candidate.getGetter(theClass, propertyName); return result; } catch (PropertyNotFoundException pnfe) { // ignore } } throw new PropertyNotFoundException("Could not find getter for " + propertyName + " on " + theClass); }
Example #18
Source File: AnyType.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int getPropertyIndex(String name) { if ( PROPERTY_NAMES[0].equals( name ) ) { return 0; } else if ( PROPERTY_NAMES[1].equals( name ) ) { return 1; } throw new PropertyNotFoundException( "Unable to locate property named " + name + " on AnyType" ); }
Example #19
Source File: CompositeCustomType.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int getPropertyIndex(String name) { String[] names = getPropertyNames(); for ( int i = 0, max = names.length; i < max; i++ ) { if ( names[i].equals( name ) ) { return i; } } throw new PropertyNotFoundException( "Unable to locate property named " + name + " on " + getReturnedClass().getName() ); }
Example #20
Source File: ComponentType.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public int getPropertyIndex(String name) { String[] names = getPropertyNames(); for ( int i = 0, max = names.length; i < max; i++ ) { if ( names[i].equals( name ) ) { return i; } } throw new PropertyNotFoundException( "Unable to locate property named " + name + " on " + getReturnedClass().getName() ); }
Example #21
Source File: ReflectHelper.java From lams with GNU General Public License v2.0 | 5 votes |
public static Method findSetterMethod(final Class containerClass, final String propertyName, final Class propertyType) { final Method setter = setterMethodOrNull( containerClass, propertyName, propertyType ); if ( setter == null ) { throw new PropertyNotFoundException( String.format( Locale.ROOT, "Could not locate setter method for property [%s#%s]", containerClass.getName(), propertyName ) ); } return setter; }
Example #22
Source File: ReflectHelper.java From lams with GNU General Public License v2.0 | 5 votes |
public static Method getterMethodOrNull(Class containerJavaType, String propertyName) { try { return findGetterMethod( containerJavaType, propertyName ); } catch (PropertyNotFoundException e) { return null; } }
Example #23
Source File: ReflectHelper.java From lams with GNU General Public License v2.0 | 5 votes |
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 ); // if no getter found yet, check all implemented interfaces if ( getter == null ) { getter = getGetterOrNull( checkClass.getInterfaces(), propertyName ); } checkClass = checkClass.getSuperclass(); } if ( getter == null ) { throw new PropertyNotFoundException( String.format( Locale.ROOT, "Could not locate getter method for property [%s#%s]", containerClass.getName(), propertyName ) ); } ensureAccessibility( getter ); return getter; }
Example #24
Source File: ReflectHelper.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Retrieve a constructor for the given class, with arguments matching the specified Hibernate mapping * {@link Type types}. * * @param clazz The class needing instantiation * @param types The types representing the required ctor param signature * @return The matching constructor. * @throws PropertyNotFoundException Indicates we could not locate an appropriate constructor (todo : again with PropertyNotFoundException???) */ public static Constructor getConstructor(Class clazz, Type[] types) throws PropertyNotFoundException { final Constructor[] candidates = clazz.getConstructors(); Constructor constructor = null; int numberOfMatchingConstructors = 0; for ( final Constructor candidate : candidates ) { final Class[] params = candidate.getParameterTypes(); if ( params.length == types.length ) { boolean found = true; for ( int j = 0; j < params.length; j++ ) { final boolean ok = types[j] == null || params[j].isAssignableFrom( types[j].getReturnedClass() ) || ( types[j] instanceof PrimitiveType && params[j] == ( (PrimitiveType) types[j] ).getPrimitiveClass() ); if ( !ok ) { found = false; break; } } if ( found ) { numberOfMatchingConstructors ++; ensureAccessibility( candidate ); constructor = candidate; } } } if ( numberOfMatchingConstructors == 1 ) { return constructor; } throw new PropertyNotFoundException( "no appropriate constructor in class: " + clazz.getName() ); }
Example #25
Source File: PojoInstantiator.java From lams with GNU General Public License v2.0 | 5 votes |
public PojoInstantiator(Class componentClass, ReflectionOptimizer.InstantiationOptimizer optimizer) { this.mappedClass = componentClass; this.isAbstract = ReflectHelper.isAbstractClass( mappedClass ); this.optimizer = optimizer; this.embeddedIdentifier = false; try { constructor = ReflectHelper.getDefaultConstructor(mappedClass); } catch ( PropertyNotFoundException pnfe ) { LOG.noDefaultConstructor(mappedClass.getName()); constructor = null; } }
Example #26
Source File: AbstractProducedQuery.java From lams with GNU General Public License v2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public QueryImplementor setProperties(Object bean) { Class clazz = bean.getClass(); String[] params = getNamedParameters(); for ( String namedParam : params ) { try { final PropertyAccess propertyAccess = BuiltInPropertyAccessStrategies.BASIC.getStrategy().buildPropertyAccess( clazz, namedParam ); final Getter getter = propertyAccess.getGetter(); final Class retType = getter.getReturnType(); final Object object = getter.get( bean ); if ( Collection.class.isAssignableFrom( retType ) ) { setParameterList( namedParam, (Collection) object ); } else if ( retType.isArray() ) { setParameterList( namedParam, (Object[]) object ); } else { Type type = determineType( namedParam, retType ); setParameter( namedParam, object, type ); } } catch (PropertyNotFoundException pnfe) { // ignore } } return this; }
Example #27
Source File: PropertyAccessStrategyChainedImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public PropertyAccess buildPropertyAccess(Class containerJavaType, String propertyName) { for ( PropertyAccessStrategy candidate : chain ) { try { return candidate.buildPropertyAccess( containerJavaType, propertyName ); } catch (Exception ignore) { // ignore } } throw new PropertyNotFoundException( "Could not resolve PropertyAccess for " + propertyName + " on " + containerJavaType ); }
Example #28
Source File: PropertyAccessMixedImpl.java From lams with GNU General Public License v2.0 | 5 votes |
protected static Field fieldOrNull(Class containerJavaType, String propertyName) { try { return ReflectHelper.findField( containerJavaType, propertyName ); } catch (PropertyNotFoundException e) { return null; } }
Example #29
Source File: MapAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public Setter getSetter(Class theClass, String propertyName) throws PropertyNotFoundException { return new MapSetter(propertyName); }
Example #30
Source File: MapAccessor.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
public Getter getGetter(Class theClass, String propertyName) throws PropertyNotFoundException { return new MapGetter(propertyName); }