diff --git modules/field/tests/field_test.entity.inc modules/field/tests/field_test.entity.inc
index 353bb3d..61676f9 100644
--- modules/field/tests/field_test.entity.inc
+++ modules/field/tests/field_test.entity.inc
@@ -62,13 +62,16 @@ function field_test_entity_info() {
       'bundles' => array('bundle1' => array('label' => 'Bundle1'), 'bundle2' => array('label' => 'Bundle2')),
       'view modes' => $test_entity_modes,
     ),
+    // In this case, the bundle key is not stored in the database.
     'test_entity_bundle' => array(
       'name' => t('Test Entity with a specified bundle.'),
       'base table' => 'test_entity_bundle',
       'fieldable' => TRUE,
+      'controller class' => 'TestEntityBundleController',
       'field cache' => FALSE,
       'entity keys' => array(
         'id' => 'ftid',
+        'bundle' => 'fttype',
       ),
       'bundles' => array('test_entity_2' => array('label' => 'Test entity 2')),
       'view modes' => $test_entity_modes,
@@ -409,3 +412,21 @@ function field_test_entity_form_submit_builder($form, &$form_state) {
   entity_form_submit_build_entity('test_entity', $entity, $form, $form_state);
   return $entity;
 }
+
+/**
+ * Controller class for the test_entity_bundle entity.
+ *
+ * This extends the DrupalDefaultEntityController class, adding required
+ * special handling for bundles (since they are not stored in the database).
+ */
+class TestEntityBundleController extends DrupalDefaultEntityController {
+
+  protected function attachLoad(&$entities, $revision_id = FALSE) {
+    // Setup standard comment properties.
+    foreach ($entities as $key => $entity) {
+      $entity->fttype = 'test_entity_bundle';
+      $entities[$key] = $entity;
+    }
+    parent::attachLoad($entities, $revision_id);
+  }
+}
\ No newline at end of file
diff --git modules/simpletest/tests/entity_query.test modules/simpletest/tests/entity_query.test
index 171c517..7aa4963 100644
--- modules/simpletest/tests/entity_query.test
+++ modules/simpletest/tests/entity_query.test
@@ -113,7 +113,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
 
     $entity = new stdClass();
     $entity->ftid = 5;
-    $entity->fttype = 'bundle2';
+    $entity->fttype = 'test_entity_bundle';
     $entity->{$this->field_names[1]}[LANGUAGE_NONE][0]['shape'] = 'square';
     $entity->{$this->field_names[1]}[LANGUAGE_NONE][0]['color'] = 'red';
     $entity->{$this->field_names[1]}[LANGUAGE_NONE][1]['shape'] = 'circle';
@@ -164,6 +164,14 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
    * Tests EntityFieldQuery.
    */
   function testEntityFieldQuery() {
+    $query = new EntityFieldQuery();
+    $query
+      ->entityCondition('entity_type', 'test_entity_bundle')
+      ->entityCondition('entity_id', '5');
+    $this->assertEntityFieldQuery($query, array(
+      array('test_entity_bundle', 5),
+    ), t('Test query on an entity type with a generated bundle.'));
+
     // Test entity_type condition.
     $query = new EntityFieldQuery();
     $query->entityCondition('entity_type', 'test_entity_bundle_key');
@@ -974,6 +982,7 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
     for ($i = 6; $i < 10; $i++) {
       $entity = new stdClass();
       $entity->ftid = $i;
+      $entity->fttype = 'test_entity_bundle';
       $entity->{$this->field_names[0]}[LANGUAGE_NONE][0]['value'] = $i - 5;
       drupal_write_record('test_entity_bundle', $entity);
       field_attach_insert('test_entity_bundle', $entity);
@@ -1112,15 +1121,20 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
    */
   function assertEntityFieldQuery($query, $intended_results, $message, $ordered = FALSE) {
     $results = array();
-    foreach ($query->execute() as $entity_type => $entity_ids) {
-      foreach ($entity_ids as $entity_id => $stub_entity) {
-        $results[] = array($entity_type, $entity_id);
+    try {
+      foreach ($query->execute() as $entity_type => $entity_ids) {
+        foreach ($entity_ids as $entity_id => $stub_entity) {
+          $results[] = array($entity_type, $entity_id);
+        }
+      }
+      if (!isset($ordered) || !$ordered) {
+        sort($results);
+        sort($intended_results);
       }
+      $this->assertEqual($results, $intended_results, $message);
     }
-    if (!isset($ordered) || !$ordered) {
-      sort($results);
-      sort($intended_results);
+    catch (Exception $e) {
+      $this->fail('Exception thrown: '. $e->getMessage());
     }
-    $this->assertEqual($results, $intended_results, $message);
   }
 }
