anchor.diff:    end.join(', ')
   %> )
     {
  -    final String sql =
  -      "<%= j_escape_string("INSERT INTO #{entity.sync.sync_temp_entity.sql.qualified_table_name} (#{entity.sync.sync_temp_entity.attribute_by_name(:MappingSource).sql.quoted_column_name}, #{entity.sync.sync_temp_entity.attribute_by_name(:MappingKey).sql.quoted_column_name}, #{entity.sync.sync_temp_entity.attribute_by_name(:MappingID).sql.quoted_column_name}, #{entity.sync.attributes_to_synchronize.select{|a| a.name.to_s != 'MappingID' && a.name.to_s != 'MappingKey'}.collect{|a| entity.sync.sync_temp_entity.attribute_by_name(a.reference? ? "#{a.name}MappingID" : a.name).sql.quoted_column_name }.join(', ')}) VALUES (?,?,#{entity.sync.attributes_to_synchronize.select{|a| a.name.to_s != 'MappingID'}.collect{|a| '?'}.join(',')})") %>";
  +    final String sql = generate<%= entity.qualified_name.gsub('.','') %>Sql( "<%= j_escape_string("SELECT ?,?,#{entity.sync.attributes_to_synchronize.select{|a| a.name.to_s != 'MappingID'}.collect{|a| '?'}.join(',')}") %>" );
   
       return getEntityManager().createNativeQuery( sql ).
         setParameter( 1, mappingSourceCode ).
  
positive.code:   }
  <% data_module.sync.entities_to_synchronize.each do |entity|
  
    sync_attribtues = entity.sync.attributes_to_synchronize.collect{|a| entity.sync.sync_temp_entity.attribute_by_name(a.reference? ? "#{a.name}MappingID" : a.name) }
  -%>
  
    public void resetIdentity<%= entity.qualified_name.gsub('.','') %>()
  
negative.code:     return getEntityManager().createNativeQuery( "<%= j_escape_string( "DELETE FROM #{entity.sync.sync_temp_entity.sql.qualified_table_name} WHERE #{entity.sync.sync_temp_entity.attribute_by_name(:MappingSource).sql.quoted_column_name} = ?") %>" ).setParameter( 1, mappingSourceCode ).executeUpdate();
    }
  
    @javax.annotation.Nonnull
    private String generate<%= entity.qualified_name.gsub('.','') %>Sql( @javax.annotation.Nonnull final String selectSql )
    {
      return
        "<%= j_escape_string( "WITH CTE(#{entity.sync.sync_temp_entity.attribute_by_name(:MappingSource).sql.quoted_column_name }, #{sync_attributes.collect{|a| a.sql.quoted_column_name }.join(', ') }) AS ") %>\n" +
        "(\n" +
        selectSql + "\n" +
        ")\n" +
        "<%= j_escape_string( "INSERT INTO #{entity.sync.sync_temp_entity.sql.qualified_table_name} (#{entity.sync.sync_temp_entity.attribute_by_name(:MappingSource).sql.quoted_column_name }, #{sync_attributes.collect{|a| a.sql.quoted_column_name }.join(', ') })") %>\n" +
        "  SELECT \n" +
        "    <%= entity.sync.sync_temp_entity.attribute_by_name(:MappingSource).sql.quoted_column_name %>, \n" +
  <%
    sync_attributes.each_with_index do |a, i|
   comma = i == sync_attributes.size - 1 ? '' : ','
    if immutable_sync_attributes.size > 0 && a.name == :MappingKey -%>
        "    SyncTemp.fnConvertBinaryToBase64(HASHBYTES('SHA1', <%= immutable_sync_attributes.collect{|other| "CONVERT(VARCHAR(50),#{j_escape_string(other.sql.quoted_column_name)})"}.join(" + '.' + ") %>))<%= comma %> \n"+
  <% else -%>
        "    <%= j_escape_string(a.sql.quoted_column_name) %><%= comma %> \n" +
  <% end -%>
  <% end -%>
        "  FROM CTE";
    }
  
    public int insert<%= entity.qualified_name.gsub('.','') %>BySql( @javax.annotation.Nonnull final String selectSql )
    {
      return executeUpdate( generate<%= entity.qualified_name.gsub('.','') %>Sql( selectSql ) );
    }
  
    public int insert<%= entity.qualified_name.gsub('.','') %>BySql( @javax.annotation.Nonnull final java.lang.String mappingSourceCode, @javax.annotation.Nonnull final String selectSql )
    {
      return executeUpdate( mappingSourceCode, generate<%= entity.qualified_name.gsub('.','') %>Sql( selectSql ) );
    }
  
    public int insert<%= entity.qualified_name.gsub('.','') %>( @javax.annotation.Nonnull final java.lang.String mappingSourceCode, @javax.annotation.Nonnull final java.lang.String mappingID, <%=
  