Buggy code:
@ Repository public class EmployeeDAO implements AbstractDAO < Employee > { private JdbcTemplate jdbcTemplate ; @ Autowired public void setDataSource ( DataSource dataSource ) { } public long nextval ( ) { } @ Override public void save ( Employee employee ) { } @ Override public Employee getById ( long id ) { } @ Override public void update ( final Employee employee ) { } @ Override public void deleteById ( long id ) { } @ Override public List < Employee > search ( Map < String , Object > parameters ) { StringBuilder sql = new StringBuilder ( ) ; sql . append ( "SELECT<seq2seq4repair_space>" ) ; sql . append ( "e.id,<seq2seq4repair_space>" ) ; sql . append ( "e.department_id,<seq2seq4repair_space>" ) ; sql . append ( "(SELECT<seq2seq4repair_space>d.name<seq2seq4repair_space>FROM<seq2seq4repair_space>departments<seq2seq4repair_space>d<seq2seq4repair_space>WHERE<seq2seq4repair_space>d.id<seq2seq4repair_space>=<seq2seq4repair_space>e.department_id)<seq2seq4repair_space>department_name,<seq2seq4repair_space>" ) ; sql . append ( "e.first_name,<seq2seq4repair_space>" ) ; sql . append ( "e.last_name,<seq2seq4repair_space>" ) ; sql . append ( "e.salary,<seq2seq4repair_space>" ) ; sql . append ( "e.birthdate,<seq2seq4repair_space>" ) ; sql . append ( "e.active<seq2seq4repair_space>" ) ; sql . append ( "FROM<seq2seq4repair_space>employees<seq2seq4repair_space>e<seq2seq4repair_space>" ) ; sql . append ( "WHERE<seq2seq4repair_space>1<seq2seq4repair_space>=<seq2seq4repair_space>1<seq2seq4repair_space>" ) ; List < Object > args = new ArrayList < Object > ( ) ; if ( parameters . containsKey ( "firstName" ) ) { sql . append ( "AND<seq2seq4repair_space>e.first_name<seq2seq4repair_space>LIKE<seq2seq4repair_space>?<seq2seq4repair_space>" ) ; args . add ( parameters . get ( "firstName" ) ) ; } if ( parameters . containsKey ( "lastName" ) ) { <START_BUG> sql . append ( "AND<seq2seq4repair_space>e.lastName<seq2seq4repair_space>LIKE<seq2seq4repair_space>?<seq2seq4repair_space>" ) ; <END_BUG> args . add ( parameters . get ( "lastName" ) ) ; } if ( parameters . containsKey ( "departmentName" ) ) { sql . append ( "AND<seq2seq4repair_space>e.department_id<seq2seq4repair_space>IN<seq2seq4repair_space>(SELECT<seq2seq4repair_space>d.id<seq2seq4repair_space>FROM<seq2seq4repair_space>departments<seq2seq4repair_space>d<seq2seq4repair_space>where<seq2seq4repair_space>d.name<seq2seq4repair_space>LIKE<seq2seq4repair_space>?)<seq2seq4repair_space>" ) ; args . add ( parameters . get ( "departmentName" ) ) ; } if ( parameters . containsKey ( "salary" ) ) { } if ( parameters . containsKey ( "birthdate" ) ) { sql . append ( "AND<seq2seq4repair_space>e.birthdate<seq2seq4repair_space>=<seq2seq4repair_space>?<seq2seq4repair_space>" ) ; args . add ( parameters . get ( "birthdate" ) ) ; } if ( parameters . containsKey ( "active" ) ) { sql . append ( "AND<seq2seq4repair_space>e.active<seq2seq4repair_space>=<seq2seq4repair_space>?<seq2seq4repair_space>" ) ; args . add ( parameters . get ( "active" ) ) ; } List < Employee > result = jdbcTemplate . query ( sql . toString ( ) , args . toArray ( ) , new EmployeeDAO . EmployeeRowMapper ( ) ) ; return result ; } private static class EmployeeRowMapper implements RowMapper < Employee > { @ Override public Employee mapRow ( ResultSet rs , int rowNum ) throws SQLException { } } }

Fix:
sql . append ( "AND<seq2seq4repair_space>e.last_name<seq2seq4repair_space>LIKE<seq2seq4repair_space>?<seq2seq4repair_space>" ) ;