Buggy code:
@ CacheNamespace ( implementation = EhcacheCache . class ) public interface SubmissionMapper { @ Select ( "SELECT<seq2seq4repair_space>*<seq2seq4repair_space>FROM<seq2seq4repair_space>voj_submissions<seq2seq4repair_space>WHERE<seq2seq4repair_space>submission_id<seq2seq4repair_space>=<seq2seq4repair_space>#{submissionId}" ) @ Options ( useCache = true ) @ Results ( { @ Result ( property = "submissionId" , column = "submission_id" ) , @ Result ( property = "problem" , column = "problem_id" , javaType = Problem . class , one = @ One ( select = "com.trunkshell.voj.mapper.ProblemMapper.getProblem" ) ) , @ Result ( property = "user" , column = "uid" , javaType = User . class , one = @ One ( select = "com.trunkshell.voj.mapper.UserMapper.getUserUsingUid" ) ) , @ Result ( property = "language" , column = "language_id" , javaType = Language . class , one = @ One ( select = "com.trunkshell.voj.mapper.LanguageMapper.getLanguageUsingId" ) ) , @ Result ( property = "submitTime" , column = "submission_submit_time" ) , @ Result ( property = "executeTime" , column = "submission_execute_time" ) , @ Result ( property = "usedTime" , column = "submission_used_time" ) , @ Result ( property = "usedMemory" , column = "submission_used_memory" ) , @ Result ( property = "judgeResult" , column = "submission_judge_result" , javaType = JudgeResult . class , one = @ One ( select = "com.trunkshell.voj.mapper.JudgeResultMapper.getJudgeResultUsingSlug" ) ) , @ Result ( property = "judgeScore" , column = "submission_judge_score" ) , @ Result ( property = "judgeLog" , column = "submission_judge_log" ) , @ Result ( property = "code" , column = "submission_code" ) } ) public Submission getSubmission ( @ Param ( "submissionId" ) long submissionId ) { } @ Select ( "SELECT<seq2seq4repair_space>*<seq2seq4repair_space>FROM<seq2seq4repair_space>voj_submissions<seq2seq4repair_space>ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>submission_id<seq2seq4repair_space>DESC<seq2seq4repair_space>LIMIT<seq2seq4repair_space>#{limit}" ) @ Options ( useCache = true ) @ Results ( { @ Result ( property = "submissionId" , column = "submission_id" ) , @ Result ( property = "problem" , column = "problem_id" , javaType = Problem . class , one = @ One ( select = "com.trunkshell.voj.mapper.ProblemMapper.getProblem" ) ) , @ Result ( property = "user" , column = "uid" , javaType = User . class , one = @ One ( select = "com.trunkshell.voj.mapper.UserMapper.getUserUsingUid" ) ) , @ Result ( property = "language" , column = "language_id" , javaType = Language . class , one = @ One ( select = "com.trunkshell.voj.mapper.LanguageMapper.getLanguageUsingId" ) ) , @ Result ( property = "submitTime" , column = "submission_submit_time" ) , @ Result ( property = "usedTime" , column = "submission_used_time" ) , @ Result ( property = "usedMemory" , column = "submission_used_memory" ) , @ Result ( property = "judgeResult" , column = "submission_judge_result" , javaType = JudgeResult . class , one = @ One ( select = "com.trunkshell.voj.mapper.JudgeResultMapper.getJudgeResultUsingSlug" ) ) , @ Result ( property = "judgeScore" , column = "submission_judge_score" ) } ) public List < Submission > getSubmissions ( @ Param ( "limit" ) int limit ) { } @ Select ( "SELECT<seq2seq4repair_space>*<seq2seq4repair_space>FROM<seq2seq4repair_space>voj_submissions<seq2seq4repair_space>WHERE<seq2seq4repair_space>submission_id<seq2seq4repair_space><=<seq2seq4repair_space>#{submissionId}<seq2seq4repair_space>ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>submission_id<seq2seq4repair_space>DESC<seq2seq4repair_space>LIMIT<seq2seq4repair_space>#{limit}" ) @ Options ( useCache = true ) @ Results ( { @ Result ( property = "submissionId" , column = "submission_id" ) , @ Result ( property = "problem" , column = "problem_id" , javaType = Problem . class , one = @ One ( select = "com.trunkshell.voj.mapper.ProblemMapper.getProblem" ) ) , @ Result ( property = "user" , column = "uid" , javaType = User . class , one = @ One ( select = "com.trunkshell.voj.mapper.UserMapper.getUserUsingUid" ) ) , @ Result ( property = "language" , column = "language_id" , javaType = Language . class , one = @ One ( select = "com.trunkshell.voj.mapper.LanguageMapper.getLanguageUsingId" ) ) , @ Result ( property = "submitTime" , column = "submission_submit_time" ) , @ Result ( property = "usedTime" , column = "submission_used_time" ) , @ Result ( property = "usedMemory" , column = "submission_used_memory" ) , @ Result ( property = "judgeResult" , column = "submission_judge_result" , javaType = JudgeResult . class , one = @ One ( select = "com.trunkshell.voj.mapper.JudgeResultMapper.getJudgeResultUsingSlug" ) ) , @ Result ( property = "judgeScore" , column = "submission_judge_score" ) } ) public List < Submission > getSubmissionsUsingOffset ( @ Param ( "submissionId" ) long offset , @ Param ( "limit" ) int limit ) { } @ Select ( "SELECT<seq2seq4repair_space>*<seq2seq4repair_space>FROM<seq2seq4repair_space>voj_submissions<seq2seq4repair_space>WHERE<seq2seq4repair_space>problem_id<seq2seq4repair_space>=<seq2seq4repair_space>#{problemId}<seq2seq4repair_space>AND<seq2seq4repair_space>uid<seq2seq4repair_space>=<seq2seq4repair_space>#{uid}<seq2seq4repair_space>ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>submission_id<seq2seq4repair_space>DESC<seq2seq4repair_space>LIMIT<seq2seq4repair_space>#{limit}" ) @ Options ( useCache = true ) @ Results ( { @ Result ( property = "submissionId" , column = "submission_id" ) , @ Result ( property = "submitTime" , column = "submission_submit_time" ) , @ Result ( property = "judgeResult" , column = "submission_judge_result" , javaType = JudgeResult . class , one = @ One ( select = "com.trunkshell.voj.mapper.JudgeResultMapper.getJudgeResultUsingSlug" ) ) } ) public List < Submission > getSubmissionUsingProblemIdAndUserId ( @ Param ( "problemId" ) long problemId , @ Param ( "uid" ) long uid , @ Param ( "limit" ) int limit ) { } <START_BUG> @ Select ( "SELECT<seq2seq4repair_space>submission_id,<seq2seq4repair_space>problem_id,<seq2seq4repair_space>submission_judge_result<seq2seq4repair_space>FROM<seq2seq4repair_space>(<seq2seq4repair_space>SELECT<seq2seq4repair_space>*<seq2seq4repair_space>FROM<seq2seq4repair_space>voj_submissions<seq2seq4repair_space>ORDER<seq2seq4repair_space>BY<seq2seq4repair_space>submission_id<seq2seq4repair_space>DESC<seq2seq4repair_space>)<seq2seq4repair_space>s<seq2seq4repair_space>WHERE<seq2seq4repair_space>uid<seq2seq4repair_space>=<seq2seq4repair_space>#{uid}<seq2seq4repair_space>AND<seq2seq4repair_space>problem_id<seq2seq4repair_space>>=<seq2seq4repair_space>#{problemIdLowerBound}<seq2seq4repair_space>AND<seq2seq4repair_space>problem_id<seq2seq4repair_space><<seq2seq4repair_space>#{problemIdUpperBound}<seq2seq4repair_space>GROUP<seq2seq4repair_space>BY<seq2seq4repair_space>problem_id" ) <END_BUG>

Fix:
@ Select ( "SELECT<seq2seq4repair_space>submission_id,<seq2seq4repair_space>s1.problem_id,<seq2seq4repair_space>submission_judge_result<seq2seq4repair_space>FROM<seq2seq4repair_space>voj_submissions<seq2seq4repair_space>s1<seq2seq4repair_space>INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>(<seq2seq4repair_space>SELECT<seq2seq4repair_space>MAX(submission_id)<seq2seq4repair_space>AS<seq2seq4repair_space>max_submission_id,<seq2seq4repair_space>problem_id<seq2seq4repair_space>FROM<seq2seq4repair_space>voj_submissions<seq2seq4repair_space>WHERE<seq2seq4repair_space>uid<seq2seq4repair_space>=<seq2seq4repair_space>#{uid}<seq2seq4repair_space>AND<seq2seq4repair_space>problem_id<seq2seq4repair_space>>=<seq2seq4repair_space>#{problemIdLowerBound}<seq2seq4repair_space>AND<seq2seq4repair_space>problem_id<seq2seq4repair_space><<seq2seq4repair_space>#{problemIdUpperBound}<seq2seq4repair_space>GROUP<seq2seq4repair_space>BY<seq2seq4repair_space>problem_id<seq2seq4repair_space>)<seq2seq4repair_space>s2<seq2seq4repair_space>ON<seq2seq4repair_space>s1.problem_id<seq2seq4repair_space>=<seq2seq4repair_space>s2.problem_id<seq2seq4repair_space>AND<seq2seq4repair_space>s1.submission_id<seq2seq4repair_space>=<seq2seq4repair_space>s2.max_submission_id" )