Is it possible to return deleted objects? I use Mysql. I want to avoid too many db requests
public interface FileRepository extends JpaRepository<File, Long> {
@Modifying
@Query(value = """
DELETE * FROM file f
WHERE f.id IN :ids
AND NOT EXISTS (SELECT * FROM time_window_file twf WHERE twf.file_id = f.id)
""", nativeQuery = true)
List<File> deleteFilesByIdsIfNotUsed(Set<Long> ids);
time_window_file has only two columns: time_window_id and file_id
With this "solution" I get the following error: [Statement.executeQuery() cannot issue statements that do not produce result sets.]
You can change your query as :
[tested in Postgres]