Buggy code:
@ Repository public class PaymentCheckPaymentDaoImpl extends MagicDao implements PaymentCheckPaymentDao { private static final String BASE_SELECT_SQL = "select<seq2seq4repair_space>a.ID,<seq2seq4repair_space>PAYMENT_ID,<seq2seq4repair_space>BANK,<seq2seq4repair_space>CHECK_DT,<seq2seq4repair_space>CHECK_NO,<seq2seq4repair_space>AMOUNT," + ( ( ( ( ( ( ( ( "<seq2seq4repair_space>b.CUSTOMER_ID,<seq2seq4repair_space>c.NAME<seq2seq4repair_space>as<seq2seq4repair_space>CUSTOMER_NAME," + "<seq2seq4repair_space>b.PAYMENT_TERMINAL_ID,<seq2seq4repair_space>d.NAME<seq2seq4repair_space>as<seq2seq4repair_space>PAYMENT_TERMINAL_NAME" ) + "<seq2seq4repair_space>from<seq2seq4repair_space>PAYMENT_CHECK_PAYMENT<seq2seq4repair_space>a" ) + "<seq2seq4repair_space>join<seq2seq4repair_space>PAYMENT<seq2seq4repair_space>b" ) + "<seq2seq4repair_space>on<seq2seq4repair_space>b.ID<seq2seq4repair_space>=<seq2seq4repair_space>a.PAYMENT_ID" ) + "<seq2seq4repair_space>join<seq2seq4repair_space>CUSTOMER<seq2seq4repair_space>c" ) + "<seq2seq4repair_space>on<seq2seq4repair_space>c.ID<seq2seq4repair_space>=<seq2seq4repair_space>b.CUSTOMER_ID" ) + "<seq2seq4repair_space>left<seq2seq4repair_space>join<seq2seq4repair_space>PAYMENT_TERMINAL<seq2seq4repair_space>d" ) + "<seq2seq4repair_space>on<seq2seq4repair_space>d.ID<seq2seq4repair_space>=<seq2seq4repair_space>b.PAYMENT_TERMINAL_ID" ) ; private PaymentCheckPaymentDaoImpl . PaymentCheckPaymentRowMapper checkRowMapper = new PaymentCheckPaymentDaoImpl . PaymentCheckPaymentRowMapper ( ) ; @ Override public void save ( PaymentCheckPayment check ) { } private static final String INSERT_SQL = "insert<seq2seq4repair_space>into<seq2seq4repair_space>PAYMENT_CHECK_PAYMENT" + "<seq2seq4repair_space>(PAYMENT_ID,<seq2seq4repair_space>BANK,<seq2seq4repair_space>CHECK_DT,<seq2seq4repair_space>CHECK_NO,<seq2seq4repair_space>AMOUNT)<seq2seq4repair_space>values<seq2seq4repair_space>(?,<seq2seq4repair_space>?,<seq2seq4repair_space>?,<seq2seq4repair_space>?,<seq2seq4repair_space>?)" ; private void insert ( final PaymentCheckPayment check ) { } private static final String UPDATE_SQL = "update<seq2seq4repair_space>PAYMENT_CHECK_PAYMENT" + ( "<seq2seq4repair_space>set<seq2seq4repair_space>BANK<seq2seq4repair_space>=<seq2seq4repair_space>?,<seq2seq4repair_space>CHECK_DT<seq2seq4repair_space>=<seq2seq4repair_space>?,<seq2seq4repair_space>CHECK_NO<seq2seq4repair_space>=<seq2seq4repair_space>?,<seq2seq4repair_space>AMOUNT<seq2seq4repair_space>=<seq2seq4repair_space>?" + "<seq2seq4repair_space>where<seq2seq4repair_space>ID<seq2seq4repair_space>=<seq2seq4repair_space>?" ) ; private void update ( PaymentCheckPayment check ) { } private static final String FIND_ALL_BY_PAYMENT_SQL = ( PaymentCheckPaymentDaoImpl . BASE_SELECT_SQL ) + "<seq2seq4repair_space>where<seq2seq4repair_space>a.PAYMENT_ID<seq2seq4repair_space>=<seq2seq4repair_space>?" ; @ Override public List < PaymentCheckPayment > findAllByPayment ( Payment payment ) { } private class PaymentCheckPaymentRowMapper implements RowMapper < PaymentCheckPayment > { @ Override public PaymentCheckPayment mapRow ( ResultSet rs , int rowNum ) throws SQLException { } } private static final String DELETE_ALL_BY_PAYMENT_SQL = "delete<seq2seq4repair_space>from<seq2seq4repair_space>PAYMENT_CHECK_PAYMENT<seq2seq4repair_space>where<seq2seq4repair_space>PAYMENT_ID<seq2seq4repair_space>=<seq2seq4repair_space>?" ; @ Override public void deleteAllByPayment ( Payment payment ) { } private static final String DELETE_SQL = "delete<seq2seq4repair_space>from<seq2seq4repair_space>PAYMENT_CHECK_PAYMENT<seq2seq4repair_space>where<seq2seq4repair_space>ID<seq2seq4repair_space>=<seq2seq4repair_space>?" ; @ Override public void delete ( PaymentCheckPayment checkPayment ) { } @ Override public List < PaymentCheckPayment > search ( PaymentCheckPaymentSearchCriteria criteria ) { List < Object > params = new ArrayList < > ( ) ; StringBuilder sql = new StringBuilder ( PaymentCheckPaymentDaoImpl . BASE_SELECT_SQL ) ; sql . append ( "<seq2seq4repair_space>where<seq2seq4repair_space>1<seq2seq4repair_space>=<seq2seq4repair_space>1" ) ; if ( ( criteria . getPaid ( ) ) != null ) { sql . append ( "<seq2seq4repair_space>and<seq2seq4repair_space>b.POST_IND<seq2seq4repair_space>=<seq2seq4repair_space>?" ) ; params . add ( ( criteria . getPaid ( ) ? "Y" : "N" ) ) ; } if ( ( criteria . getPaymentDate ( ) ) != null ) { if ( ( criteria . getTimePeriod ( ) ) != null ) { if ( ( criteria . getTimePeriod ( ) ) == ( TimePeriod . MORNING_ONLY ) ) { sql . append ( "<seq2seq4repair_space>and<seq2seq4repair_space>b.POST_DT<seq2seq4repair_space>>=<seq2seq4repair_space>?<seq2seq4repair_space>and<seq2seq4repair_space>b.POST_DT<seq2seq4repair_space><<seq2seq4repair_space>date_add(?,<seq2seq4repair_space>interval<seq2seq4repair_space>13<seq2seq4repair_space>hour)" ) ; params . add ( DbUtil . toMySqlDateString ( criteria . getPaymentDate ( ) ) ) ; params . add ( DbUtil . toMySqlDateString ( criteria . getPaymentDate ( ) ) ) ; } else if ( ( criteria . getTimePeriod ( ) ) == ( TimePeriod . AFTERNOON_ONLY ) ) { sql . append ( ( "<seq2seq4repair_space>and<seq2seq4repair_space>b.POST_DT<seq2seq4repair_space>>=<seq2seq4repair_space>date_add(?,<seq2seq4repair_space>interval<seq2seq4repair_space>13<seq2seq4repair_space>hour)" + "<seq2seq4repair_space>and<seq2seq4repair_space>b.POST_DT<seq2seq4repair_space><<seq2seq4repair_space>date_add(?,<seq2seq4repair_space>interval<seq2seq4repair_space>1<seq2seq4repair_space>day)" ) ) ; params . add ( DbUtil . toMySqlDateString ( criteria . getPaymentDate ( ) ) ) ; params . add ( DbUtil . toMySqlDateString ( criteria . getPaymentDate ( ) ) ) ; } } else { sql . append ( "<seq2seq4repair_space>and<seq2seq4repair_space>b.POST_DT<seq2seq4repair_space>>=<seq2seq4repair_space>?<seq2seq4repair_space>and<seq2seq4repair_space>b.POST_DT<seq2seq4repair_space><<seq2seq4repair_space>date_add(?,<seq2seq4repair_space>interval<seq2seq4repair_space>1<seq2seq4repair_space>day)" ) ; params . add ( DbUtil . toMySqlDateString ( criteria . getPaymentDate ( ) ) ) ; params . add ( DbUtil . toMySqlDateString ( criteria . getPaymentDate ( ) ) ) ; } } if ( ( criteria . getPaymentTerminal ( ) ) != null ) { sql . append ( "<seq2seq4repair_space>and<seq2seq4repair_space>b.PAYMENT_TERMINAL_ID<seq2seq4repair_space>=<seq2seq4repair_space>?" ) ; params . add ( criteria . getPaymentTerminal ( ) . getId ( ) ) ; } <START_BUG> sql . append ( "<seq2seq4repair_space>order<seq2seq4repair_space>by<seq2seq4repair_space>b.POST_DT" ) ; <END_BUG> return getJdbcTemplate ( ) . query ( sql . toString ( ) , checkRowMapper , params . toArray ( ) ) ; } No newline ; at end ; of file ; }

Fix:
sql . append ( "<seq2seq4repair_space>order<seq2seq4repair_space>by<seq2seq4repair_space>c.NAME,<seq2seq4repair_space>CHECK_DT" ) ;