 
 
 (defn retrieve [entity-record-type key-value &
-                {:keys [parent datastore-entity-name]
-                 :or {datastore-entity-name (unqualified-name (.getName entity-record-type))}}]
+                {:keys [parent kind]
+                 :or {kind (unqualified-name (.getName entity-record-type))}}]
   (let [key-object (if parent
                        (KeyFactory/createKey (get-key-object parent)
-                                             datastore-entity-name
+                                             kind
                                              (coerce-key-value-type key-value))
-                       (KeyFactory/createKey datastore-entity-name
+                       (KeyFactory/createKey kind
                                              (coerce-key-value-type key-value)))
         entity (.get (get-datastore-service) key-object)
         raw-properties (into {} (.getProperties entity))

         :else v)))


(defn get-key-object-helper [entity-record key-property datastore-entity-name &
                             {:keys [parent]}]
  (let [entity-record-metadata (meta entity-record)
        metadata-key-value (when entity-record-metadata (:key entity-record-metadata))



(defmacro defentity [name properties &
                     {: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)]
    `(defrecord ~name ~properties
       EntityProtocol
       (get-key-object [this#]
         (get-key-object-helper this# ~key-property ~kind))
       (get-key-object [this# parent#]
         (get-key-object-helper this# ~key-property ~kind :parent parent#))
       (save! [this#]
         (save!-helper this# ~kind))
       (save! [this# parent#]
         (save!-helper this# ~kind :parent parent#)))))


;;; Note that the code relies on the API's implicit transaction tracking, and
