private NakedCollection createAdapter( final NakedObject parent, final String fieldName, final NakedObjectSpecification specification, final Object collection, InternalCollectionKey key) { NakedCollection adapter; adapter = NakedObjectsContext.getReflector().createCollectionAdapter(collection, specification); if (parent.getResolveState().isPersistent()) { /* * don't log "collection" as this may cause it to resolve e.g. when using Hibernate, as toString * lists all objects inside the collection */ LOG.debug("creating adapter for persistent collection: " + fieldName); adapter.changeState(ResolveState.GHOST); // TODO loadEvent will create adapter for proxy, but collection is a // different matter // if adapter exists for collection it will be set to resolved in the loadEvent, but we // can't create the new adapter at that point as we can't get the field. so make sure // state is correct here. if (Hibernate.isInitialized(collection)) { adapter.changeState(ResolveState.RESOLVING); adapter.changeState(ResolveState.RESOLVED); } } else { LOG.debug("creating adapter for transient collection: " + collection); adapter.changeState(ResolveState.TRANSIENT); } return adapter; }