                                        ;; unknown type; just use a basic EntityProtocol
                                        (EntityBase.))]
                   (map #(with-meta
-                          (merge model-record (entity->properties (.getProperties %)))
+                          (merge model-record
+                                 (entity->properties (.getProperties %)
+                                                     (get-clj-properties model-record)))
                           {:key (.getKey %)})
                        results)))))
 

              model-record (record entity-record-type)]
          (map #(let [v (.getValue %)]
                  (with-meta
                    (merge model-record (entity->properties (.getProperties v)))
                    {:key (.getKey v)}))
               entities))
        ;; handles singleton values

                     {:keys [kind]
                      :or {kind (unqualified-name name)}}]
  (let [key-property-name (first (filter #(= (:tag (meta %)) :key) properties))
        key-property (if key-property-name (keyword (str key-property-name)) nil)
        ;; XXX: The keyword and str composition below works
        ;; around a weird Clojure bug (see
        ;; http://groups.google.com/group/clojure-dev/browse_thread/thread/655f6e7d1b312f17).
        clj-properties (set (map (comp keyword str)
                                 (filter #(= (:tag (meta %)) :clj) properties)))]
    `(defrecord ~name ~properties
       EntityProtocol
       (get-clj-properties [this#]
         ~clj-properties)
       (get-key-object [this#]
         (get-key-object-helper this# ~key-property ~kind nil))
       (get-key-object [this# parent#]
