(!idField.isAccessible()) { idField.setAccessible(true); } idField.set(replacement, (Integer) ((HibernateProxy) fieldValue).getHibernateLazyInitializer().getIdentifier()); } catch (Exception e) { e.printStackTrace(); System.out.println("No id constructor and unable to set field id for base bean " + className); } field.set(object, replacement); }*/ } } else { if (fieldValue instanceof org.hibernate.collection.PersistentCollection) { // Replace hibernate specific collection types if (!((org.hibernate.collection.PersistentCollection) fieldValue).wasInitialized()) { field.set(object, null); } else { Object replacement = null; if (fieldValue instanceof Map) { replacement = new HashMap((Map) fieldValue); } else if (fieldValue instanceof List) { replacement = new ArrayList((List) fieldValue); } else if (fieldValue instanceof Set) { replacement = new HashSet((Set) fieldValue); } else if (fieldValue instanceof Collection) { replacement = new ArrayList((Collection)fieldValue); } setField(object, field.getName(), replacement); nullOutUninitializedFields(replacement, nulledObjects, depth+1, serializationType); } } else { if (fieldValue != null && (fieldValue.getClass().getName().contains("org.rhq") || fieldValue instanceof Collection || fieldValue instanceof Object[] || fieldValue instanceof Map)) nullOutUninitializedFields((fieldValue), nulledObjects, depth+1, serializationType); } } if (accessModifierFlag) { field.setAccessible(false); } } } private static void nullOutFieldsByAccessors(Object value, Set<Integer> nulledObjects, int depth, SerializationType serializationType) throws Exception { // Null out any collections that aren't loaded BeanInfo bi = Introspector.getBeanInfo(value.getClass(), Object.class); PropertyDescriptor[] pds = bi.getPropertyDescriptors(); for (PropertyDescriptor pd : pds) { Object propertyValue = null; try { propertyValue = pd.getReadMethod().invoke(value); } catch (Throwable lie) { if (LOG.isDebugEnabled()) { LOG.debug("Couldn't load: " + pd.getName() + " off of " + value.getClass().getSimpleName(), lie); } } if (!Hibernate.isInitialized(propertyValue)) { try { if (LOG.isDebugEnabled()) { LOG.debug("Nulling out: " + pd.getName() + " off of " + value.getClass().getSimpleName()); } Method writeMethod = pd.getWriteMethod(); if ((writeMethod != null) && (writeMethod.getAnnotation(XmlTransient.class) == null)) { pd.getWriteMethod().invoke(value, new Object[] { null }); } else { nullOutField(value, pd.getName()); } } catch (Exception lie) { LOG.debug("Couldn't null out: " + pd.getName() + " off of " + value.getClass().getSimpleName() + " trying field access", lie); nullOutField(value, pd.getName()); } } else { if ((propertyValue instanceof Collection) || ((propertyValue != null) && propertyValue.getClass().getName().startsWith("org.rhq.core.domain"))) { nullOutUninitializedFields(propertyValue, nulledObjects, depth + 1, serializationType); } } } } private static void setField(Object object, String fieldName, Object newValue) { try { Field f = object.getClass().getDeclaredField(fieldName); if (f != null) { // try to set the field this way f.setAccessible(true); f.set(object, newValue); } } catch (NoSuchFieldException e) { // ignore this } catch (IllegalAccessException e) { // ignore this } } private static void nullOutField(Object value, String fieldName) { try { Field f = value.getClass().getDeclaredField(fieldName); if (f != null) { // try to set the field this way f.setAccessible(true); f.set(value, null); } } catch (NoSuchFieldException e) { // ignore this } catch (IllegalAccessException e) { // ignore this } } } Detalhe que eu comentei a parte do ID, pois nao e todo mundo que usa o nome "ID" como chave, portanto caso necessario implementem !Ele funciona sem a parte do id, pois objetos lazy seriam "buscados" nesse momento, caso nao haja a necessidade, deixem comentado pois ele setara NULL nos objetos.\m/(0.0)\m/Espero que tenha ajudado pessoal !Abracos !