#180 Transaction Issues When Renaming a File

Companies:
Sberbank
Themes:
SpringTransactionsCode Review

This method renames a file on disk and stores the new name in the database. What problems does it have?

SQL
@Transactional
public void process(String oldName, String newName) {
    Long id = exec("select id from file where name='" + oldName + "'"); // execute a database query
    processFile(oldName, newName); // rename the file on disk
    exec("update file set name='" + newName + "' where id = " + id); // execute a database query
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in