<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -362,55 +362,64 @@ module DataMapper
 
         sql = &quot;SELECT #{select_columns.join(', ')} FROM #{table.to_sql} WHERE #{table.keys.map { |key| &quot;#{key.to_sql} = ?&quot; }.join(' AND ')}&quot;
 
-        connection do |db|
-          reader = nil
-          begin
-            reader = db.create_command(sql).execute_reader(*keys)
+        begin
+          connection do |db|
+            reader = nil
+            begin
+              reader = db.create_command(sql).execute_reader(*keys)
 
-            if reader.has_rows?
+              if reader.has_rows?
 
-              instance_type = klass
+                instance_type = klass
 
-              if table.multi_class? &amp;&amp; table.type_column
-                value = reader.item(column_indexes[table.type_column])
-                instance_type = table.type_column.type_cast_value(value) unless value.blank?
-              end
+                if table.multi_class? &amp;&amp; table.type_column
+                  value = reader.item(column_indexes[table.type_column])
+                  instance_type = table.type_column.type_cast_value(value) unless value.blank?
+                end
 
-              if instance.nil?
-                instance = instance_type.allocate()
-                instance.instance_variable_set(:@__key, instance_id)
-                instance.instance_variable_set(:@new_record, false)
-                database_context.identity_map.set(instance)
-              elsif instance.new_record?
-                instance.instance_variable_set(:@__key, instance_id)
-                instance.instance_variable_set(:@new_record, false)
-                database_context.identity_map.set(instance)
-              end
+                if instance.nil?
+                  instance = instance_type.allocate()
+                  instance.instance_variable_set(:@__key, instance_id)
+                  instance.instance_variable_set(:@new_record, false)
+                  database_context.identity_map.set(instance)
+                elsif instance.new_record?
+                  instance.instance_variable_set(:@__key, instance_id)
+                  instance.instance_variable_set(:@new_record, false)
+                  database_context.identity_map.set(instance)
+                end
 
-              instance.database_context = database_context
+                instance.database_context = database_context
 
-              instance_type.callbacks.execute(:before_materialize, instance)
+                instance_type.callbacks.execute(:before_materialize, instance)
 
-              originals = instance.original_values
+                originals = instance.original_values
 
-              column_indexes.each_pair do |column, i|
-                value = column.type_cast_value(reader.item(i))
-                instance.instance_variable_set(column.instance_variable_name, value)
+                column_indexes.each_pair do |column, i|
+                  value = column.type_cast_value(reader.item(i))
+                  instance.instance_variable_set(column.instance_variable_name, value)
 
-                case value
-                  when String, Date, Time then originals[column.name] = value.dup
-                  else originals[column.name] = value
+                  case value
+                    when String, Date, Time then originals[column.name] = value.dup
+                    else originals[column.name] = value
+                  end
                 end
-              end
 
-              instance.loaded_set = [instance]
+                instance.loaded_set = [instance]
 
-              instance_type.callbacks.execute(:after_materialize, instance)
-            end # if reader.has_rows?
-          ensure
-            reader.close if reader &amp;&amp; reader.open?
+                instance_type.callbacks.execute(:after_materialize, instance)
+              end # if reader.has_rows?
+            ensure
+              reader.close if reader &amp;&amp; reader.open?
+            end
+          end # connection
+        rescue DataObject::QueryError =&gt; exception
+          if exception.message =~ /(Lost connection to MySQL server during query|MySQL server has gone away)/
+            create_connection
+            retry
+          else
+            raise
           end
-        end # connection
+        end
 
         return instance
       end</diff>
      <filename>lib/data_mapper/adapters/data_object_adapter.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>a884cac4072eaaa13ee4d690179e73ebffc3cc58</id>
    </parent>
  </parents>
  <author>
    <name>Lucas Carlson</name>
    <email>lucas@rufy.com</email>
  </author>
  <url>http://github.com/cardmagic/dm-works/commit/93ad19c37c9a978525ea260483ba7ecfb8877184</url>
  <id>93ad19c37c9a978525ea260483ba7ecfb8877184</id>
  <committed-date>2008-04-24T15:12:07-07:00</committed-date>
  <authored-date>2008-04-24T15:12:07-07:00</authored-date>
  <message>Fixing reconnect issue</message>
  <tree>b8e52d711dcbf49b55825c1b6c8df05c214716bd</tree>
  <committer>
    <name>Lucas Carlson</name>
    <email>lucas@rufy.com</email>
  </committer>
</commit>
