Index: addon/frontend/src/main/java/org/onehippo/taxonomy/plugin/tree/CategoryNode.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- addon/frontend/src/main/java/org/onehippo/taxonomy/plugin/tree/CategoryNode.java	(revision 1617)
+++ addon/frontend/src/main/java/org/onehippo/taxonomy/plugin/tree/CategoryNode.java	(revision )
@@ -32,7 +32,11 @@
         super(model.getTaxonomyModel(), language);
         this.model = model;
 
-        Category parentCat = getCategory().getParent();
+        final Category category = getCategory();
+        if (category == null) {
+            throw new IllegalArgumentException("Could not get a Category for '"+model.getKey()+"'.");
+        }
+        Category parentCat = category.getParent();
         if (parentCat == null) {
             parent = new TaxonomyNode(model.getTaxonomyModel(), language);
         } else {
Index: addon/frontend/src/main/java/org/onehippo/taxonomy/plugin/model/JcrTaxonomy.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- addon/frontend/src/main/java/org/onehippo/taxonomy/plugin/model/JcrTaxonomy.java	(revision 1617)
+++ addon/frontend/src/main/java/org/onehippo/taxonomy/plugin/model/JcrTaxonomy.java	(revision )
@@ -34,7 +34,9 @@
 import org.hippoecm.frontend.i18n.model.NodeTranslator;
 import org.hippoecm.frontend.model.JcrNodeModel;
 import org.hippoecm.frontend.session.UserSession;
+import org.hippoecm.repository.api.HippoNode;
 import org.hippoecm.repository.api.HippoSession;
+import org.hippoecm.repository.util.NodeIterable;
 import org.onehippo.taxonomy.api.TaxonomyNodeTypes;
 import org.onehippo.taxonomy.plugin.api.EditableTaxonomy;
 import org.onehippo.taxonomy.plugin.api.TaxonomyException;
@@ -133,16 +135,12 @@
         }
     }
 
-    /**
-     * Locate item by uuid.  The implementation uses a search to find the node, so it is imperative that the item has
-     * been saved.
-     */
     public JcrCategory getCategoryByKey(String key) {
         if (key == null) {
             return null;
         }
 
-        loadCategoriesFromIndex();
+        loadCategories();
 
         JcrCategory category = categories.get(key);
         if (category != null) {
@@ -155,73 +153,47 @@
             } catch (RepositoryException e) {
                 log.error("failed to find category by key " + key, e);
             }
+        }
-            return null;
-        }
+        return null;
+    }
 
+    private void loadCategories() {
+        if (categories == null) {
+            categories = new TreeMap<String, JcrCategory>();
-        try {
+            try {
-            Session session = ((UserSession) org.apache.wicket.Session.get()).getJcrSession();
-            HippoSession hippoSession = (HippoSession) session;
-            NodeIterator nodeIter = hippoSession.pendingChanges(getNode(),
-                    TaxonomyNodeTypes.NODETYPE_HIPPOTAXONOMY_CATEGORY);
-            while (nodeIter.hasNext()) {
-                Node node = nodeIter.nextNode();
-                if (node != null) {
-                    try {
-                        if (node.getProperty(TaxonomyNodeTypes.HIPPOTAXONOMY_KEY).getString().equals(key)) {
-                            return toCategory(new JcrNodeModel(node), editable);
+                Node taxonomyRootNode = getNode();
+                if (!taxonomyRootNode.isNodeType(TaxonomyNodeTypes.NODETYPE_HIPPOTAXONOMY_TAXONOMY)) {
+                    log.warn("Expected taxonomy  node of type {} for node {} but was of type {}",
+                            new String[]{TaxonomyNodeTypes.NODETYPE_HIPPOTAXONOMY_TAXONOMY, taxonomyRootNode.getPath(), taxonomyRootNode.getPrimaryNodeType().getName()});
+                    return;
-                        }
+                }
+                loadCategories(taxonomyRootNode);
+
+            } catch (RepositoryException ex) {
+                log.error("failed to load categories", ex);
-                    }
+            }
-                    catch (RepositoryException re) {
-                        if (log.isDebugEnabled()) {
-                            log.debug("Can't create category by key " + key, re);
-                        }
+        }
-                        else {
-                            log.warn("Can't create category by key {}, message is {}", key, re.getMessage());
-                        }
+    }
+
+    private void loadCategories(final Node node) throws RepositoryException {
+        if (node instanceof HippoNode) {
+            if (((HippoNode)node).isVirtual())  {
+                return;
-                    }
+            }
-                    catch (TaxonomyException te) {
-                        log.warn("TaxonomyException: can't create category by key {}, message is {}", key, te.getMessage());
-                    }
+        }
-                }
-            }
-            log.info("no category found with key " + key);
-        } catch (RepositoryException ex) {
-            log.error("failed to find category by key " + key, ex);
-        }
-        return null;
-    }
-
-    private void loadCategoriesFromIndex() {
-        if (categories == null) {
-            categories = new TreeMap<String, JcrCategory>();
+        for (Node child : new NodeIterable(node.getNodes())) {
             try {
-                Session session = ((UserSession) org.apache.wicket.Session.get()).getJcrSession();
-                QueryManager qMgr = session.getWorkspace().getQueryManager();
-                String startPath = getNode().getPath() + "/";
-                Query query = qMgr.createQuery("//element(*, " + TaxonomyNodeTypes.NODETYPE_HIPPOTAXONOMY_CATEGORY + ")", Query.XPATH);
-                NodeIterator result = query.execute().getNodes();
-                while (result.hasNext()) {
-                    Node node = result.nextNode();
-                    if (node != null) {
-                        try {
-                            if (node.getPath().startsWith(startPath)) {
-                                JcrCategory category = toCategory(new JcrNodeModel(node), editable);
+                if (child.isNodeType(TaxonomyNodeTypes.NODETYPE_HIPPOTAXONOMY_CATEGORY)) {
+                    JcrCategory category = toCategory(new JcrNodeModel(child), editable);
-                                categories.put(category.getKey(), category);
+                    categories.put(category.getKey(), category);
+                    loadCategories(child);
-                            }
+                }
-                        } catch (RepositoryException re) {
+            } catch (TaxonomyException e) {
-                            if (log.isDebugEnabled()) {
+                if (log.isDebugEnabled()) {
-                                log.debug("Failed to load category from below " + startPath, re);
+                    log.warn("TaxonomyException: failed to load category from below {} : {}", node.getPath() , e);
+                } else {
+                    log.warn("TaxonomyException: failed to load category from below {}, message is {}", node.getPath() , e.toString());
-                            }
+                }
-                            else {
-                                log.warn("Failed to load category from below {}, message is {}", startPath, re.getMessage());
-                            }
-                        } catch (TaxonomyException te) {
-                            log.warn("TaxonomyException: failed to load category from below {}, message is {}", startPath, te.getMessage());
-                        }
-                    }
-                }
-            } catch (RepositoryException ex) {
-                log.error("failed to load categories", ex);
             }
         }
     }
Index: addon/frontend/src/main/java/org/onehippo/taxonomy/plugin/model/CategoryModel.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- addon/frontend/src/main/java/org/onehippo/taxonomy/plugin/model/CategoryModel.java	(revision 1617)
+++ addon/frontend/src/main/java/org/onehippo/taxonomy/plugin/model/CategoryModel.java	(revision )
@@ -31,6 +31,10 @@
         this.key = key;
     }
 
+    public String getKey() {
+        return key;
+    }
+
     public IModel<Taxonomy> getTaxonomyModel() {
         return taxonomyModel;
     }
