title: Using java google app engine bulkloader.yaml to upload data with export_transform on __key__ changes ID/NAME coloumn from id (long) to name (string)
body: <p>I think my question is similar to: <a href="https://stackoverflow.com/questions/3749806/bulkloader-export-transform">BulkLoader -export_transform</a> OR <a href="https://stackoverflow.com/questions/3220911/gae-datastore-export-transform">https://stackoverflow.com/questions/3220911/gae-datastore-export-transform</a></p>
  
  <p>Basically, I'm using the bulkloader to backup and restore entities that I've created.
  To test I'm using the <strong>"Game"</strong> kind and outputting it to a csv file called game.csv.</p>
  
  <p>This is the process I go through:</p>
  
  <ol>
  <li><p>Download the game kind to game.csv using:</p>
  
  <p>appcfg.py download_data --config_file=bulkloader.yaml --kind=Game --filename=game.csv --application=MyAppId --url=<a href="http://MyAppId.appspot.com/remote_api" rel="nofollow noreferrer">http://MyAppId.appspot.com/remote_api</a> --rps_limit=500 --bandwidth_limit=2500000 --batch_size=100</p></li>
  <li><p>Delete all game entities. I then checked the my app's admin portal datastore viewer tab and I see that there are no more entities in my data store.</p></li>
  <li><p>Upload the game kind using the game.csv created using (command is the same as <strong>download_data</strong> but with <strong>upload_data</strong>):</p>
  
  <p>appcfg.py upload_data --config_file=bulkloader.yaml --kind=Game --filename=game.csv --application=MyAppId --url=<a href="http://MyAppId.appspot.com/remote_api" rel="nofollow noreferrer">http://MyAppId.appspot.com/remote_api</a> --rps_limit=500 --bandwidth_limit=2500000 --batch_size=100</p></li>
  <li><p>Run a servlet that retrieves an entity by 'name' (this is the property shown in Game.java below). </p></li>
  </ol>
  
  <p>The following error occurs:</p>
  
  <pre><code>Uncaught exception from servlet
  java.lang.IllegalStateException: Loaded Entity has name but com.example.app.model.Game has no String @Id
      at com.googlecode.objectify.impl.ConcreteEntityMetadata.setKey(ConcreteEntityMetadata.java:343)
      at com.googlecode.objectify.impl.ConcreteEntityMetadata.toObject(ConcreteEntityMetadata.java:210)
      at com.googlecode.objectify.impl.QueryImpl$ToObjectIterator.translate(QueryImpl.java:640)
      at com.googlecode.objectify.impl.QueryImpl$ToObjectIterator.translate(QueryImpl.java:629)
      at com.googlecode.objectify.util.TranslatingIterator.next(TranslatingIterator.java:35)
      at com.googlecode.objectify.impl.QueryImpl.list(QueryImpl.java:470)
  </code></pre>
  
  <p>I suspect it has something to do with my <strong>bulkloader.yaml</strong> file not being configure correct for the <code>__key__</code> property. So I've posted it below:</p>
  
  <pre><code>- import: google.appengine.ext.bulkload.transform
  - import: google.appengine.ext.bulkload.bulkloader_wizard
  - import: google.appengine.ext.db
  - import: google.appengine.api.datastore
  - import: google.appengine.api.users
  
  transformers:
  
  - kind: Game
    connector: csv
    connector_options:
      # TODO: Add connector options here--these are specific to each connector.
    property_map:
      - property: __key__
        external_name: key
        export_transform: transform.key_id_or_name_as_string
  
      - property: __scatter__
        #external_name: __scatter__
        # Type: ShortBlob Stats: 56 properties of this type in this kind.
  
      - property: genre
        external_name: genre
        # Type: String Stats: 6639 properties of this type in this kind.
  
      - property: name
        external_name: name
        # Type: String Stats: 6639 properties of this type in this kind.
  
      - property: releasedate
        external_name: releasedate
        # Type: Date/Time Stats: 6548 properties of this type in this kind.
        import_transform: transform.import_date_time('%Y-%m-%dT%H:%M:%S')
        export_transform: transform.export_date_time('%Y-%m-%dT%H:%M:%S')
  </code></pre>
  
  <p>Prior to the deletion and upload of data, the <strong>"Game"</strong> kind (within the datastore viewer tab of the app's admin portal) shows the <code>ID/NAME</code> column with hyperlinks that look like <strong>ID=12345</strong>, <strong>ID=67890</strong> ... for each entitiy row.</p>
  
  <p>After the upload the datastire viewer shows the <code>ID/NAME</code> column with hyperlinks that look like <strong>NAME=12345</strong>, <strong>NAME=67890</strong> ... for each entitiy row.</p>
  
  <hr>
  
  <h2>Possible cause?</h2>
  
  <p>I've actually posted my question on, <a href="https://groups.google.com/forum/?hl=en#!topic/objectify-appengine/FFuB2Onfnzc" rel="nofollow noreferrer">https://groups.google.com/forum/?hl=en#!topic/objectify-appengine/FFuB2Onfnzc</a> but we don't know the syntax to avoid transforming the <code>__key__</code> property to string when uploading back the data.</p>
  
  <p>Jeff (creator of Objectify3.0) says:</p>
  
  <p><em>The error message says that the data in the datastore as a String name
  key, but your Game entity has a numeric Long @Id.  I don't really know
  the syntax for the bulk loader, but the most suspect line is this one:</em></p>
  
  <pre><code>export_transform: transform.key_id_or_name_as_string
  </code></pre>
  
  <p><em>It looks like you are converting all numeric ids to strings here,
  which would be your problem.  Leave them as numbers.</em></p>
  
  <p>I've tried removing the <code>export_transform: transform.key_id_or_name_as_string</code> but when I do the download the csv file is empty.</p>
  
  <p>Maybe a solution is to avoid using the <code>--config_file</code> parameter and <strong>bulkloader.yaml</strong> file and just let the bulkloader download/upload the data without any transformations?</p>
  
  <hr>
  
  <h2>Extra information incase it might be relevant</h2>
  
  <p>I'm using the objectify3.0.jar to manipulate my GAE datastore. So my Game kind looks like this:</p>
  
  <pre><code>public class Game {
      @Id private Long id; //This is my key property, auto generated by objectify  
      private String name;
      private String genre; 
      private Date releasedate;
  
      //ommitting getters and setters 
  }
  </code></pre>