anchor.diff:        "<%= j_escape_string(" JOIN #{ entity.sync.sync_temp_entity.sql.qualified_table_name } T ON M.#{ entity.sync.master_entity.attribute_by_name(:MappingSource).sql.quoted_column_name } = T.#{ entity.sync.sync_temp_entity.attribute_by_name(:MappingSource).sql.quoted_column_name } AND M.#{ entity.sync.master_entity.attribute_by_name(:MappingKey).sql.quoted_column_name } = T.#{ entity.sync.sync_temp_entity.attribute_by_name(:MappingKey).sql.quoted_column_name} AND M.#{entity.sync.master_entity.attribute_by_name(:MappingID).sql.quoted_column_name } = T.#{ entity.sync.sync_temp_entity.attribute_by_name(:MappingID).sql.quoted_column_name } AND M.#{ entity.sync.master_entity.attribute_by_name(:DeletedAt).sql.quoted_column_name } IS NULL ") %>" +
   <% reference_index = 0 -%>
   <%
  -  entity.sync.attributes_to_synchronize.select{|a| a.reference? }.each do |a|
  +  entity.sync.attributes_to_update.select{|a| a.reference? }.each do |a|
      reference_index += 1
   -%>
   <% if a.referenced_entity.abstract? -%>
  
positive.code:     final String sql =
        "<%= j_escape_string("UPDATE #{entity.sql.dialect.requires_table_name_for_update ? "#{entity.sync.master_entity.sql.qualified_table_name}" : "M"}") %>" +
        "<%= j_escape_string(" SET #{entity.sync.master_entity.attribute_by_name(:MasterSynchronized).sql.quoted_column_name} = #{entity.sql.dialect.false_sql}, ") %>" +
        "<%= j_escape_string("     #{entity.sync.attributes_to_synchronize.select{|a| ![:MappingKey, :MappingID].include?(a.name)}.collect{|a| "#{entity.sync.master_entity.attribute_by_name(a.name).sql.quoted_column_name} = #{
  if a.reference?
    reference_index += 1
    col_name = entity.sync.master_entity.attribute_by_name(a.name).referenced_entity.primary_key.sql.quoted_column_name
  
negative.code:       "<%= j_escape_string("   M.#{ entity.sync.master_entity.attribute_by_name(:MappingSource).sql.quoted_column_name } = ? AND ") %>" +
  <%
    reference_index = 0
    entity.sync.attributes_to_update.select{|a| a.reference? }.each do |a|
      reference_index += 1
      next unless a.nullable?
  -%>
  