Buggy code:
@ Repository public class SalaryDaoImpl implements SalaryDao { @ PersistenceContext private EntityManager entityManager ; @ Override public void save ( Salary salary ) { } @ Override public Salary get ( long id ) { } @ Override public List < Salary > getAllCurrent ( ) { } @ Override public Salary findByEmployeeAndEffectiveDate ( Employee employee , Date effectiveDate ) { } @ Override public void delete ( Salary salary ) { } @ Override public List < Salary > findAllCurrentByPayPeriod ( PayPeriod payPeriod ) { } @ Override public List < Salary > search ( SalarySearchCriteria criteria ) { Map < String , Object > paramMap = new HashMap < > ( ) ; StringBuilder sql = new StringBuilder ( "select<seq2seq4repair_space>s<seq2seq4repair_space>from<seq2seq4repair_space>Salary<seq2seq4repair_space>s<seq2seq4repair_space>where<seq2seq4repair_space>1<seq2seq4repair_space>=<seq2seq4repair_space>1" ) ; if ( ( criteria . getEmployee ( ) ) != null ) { sql . append ( "<seq2seq4repair_space>and<seq2seq4repair_space>s.employee<seq2seq4repair_space>=<seq2seq4repair_space>:employee" ) ; paramMap . put ( "employee" , criteria . getEmployee ( ) ) ; } if ( ( criteria . getEffectiveDateFrom ( ) ) != null ) { <START_BUG> sql . append ( "<seq2seq4repair_space>and<seq2seq4repair_space>(" ) . append ( "s.effectiveDateFrom<seq2seq4repair_space>>=<seq2seq4repair_space>:effectiveDateFrom" ) . append ( "<seq2seq4repair_space>or<seq2seq4repair_space>(s.effectiveDateFrom<seq2seq4repair_space><=<seq2seq4repair_space>:effectiveDateFrom<seq2seq4repair_space>and<seq2seq4repair_space>s.effectiveDateTo<seq2seq4repair_space>>=<seq2seq4repair_space>:effectiveDateFrom)" ) . append ( ")" ) ; <END_BUG> paramMap . put ( "effectiveDateFrom" , criteria . getEffectiveDateFrom ( ) ) ; } if ( ( criteria . getEffectiveDateTo ( ) ) != null ) { sql . append ( "<seq2seq4repair_space>and<seq2seq4repair_space>(" ) . append ( "s.effectiveDateTo<seq2seq4repair_space><=<seq2seq4repair_space>:effectiveDateTo" ) . append ( "<seq2seq4repair_space>or<seq2seq4repair_space>(s.effectiveDateFrom<seq2seq4repair_space><=<seq2seq4repair_space>:effectiveDateTo<seq2seq4repair_space>and<seq2seq4repair_space>(s.effectiveDateTo<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>or<seq2seq4repair_space>s.effectiveDateTo<seq2seq4repair_space>>=<seq2seq4repair_space>:effectiveDateTo))" ) . append ( ")" ) ; paramMap . put ( "effectiveDateTo" , criteria . getEffectiveDateTo ( ) ) ; } TypedQuery < Salary > query = entityManager . createQuery ( sql . toString ( ) , Salary . class ) ; for ( String key : paramMap . keySet ( ) ) { query . setParameter ( key , paramMap . get ( key ) ) ; } return query . getResultList ( ) ; } }

Fix:
sql . append ( "<seq2seq4repair_space>and<seq2seq4repair_space>(" ) . append ( "s.effectiveDateFrom<seq2seq4repair_space>>=<seq2seq4repair_space>:effectiveDateFrom" ) . append ( "<seq2seq4repair_space>or<seq2seq4repair_space>(s.effectiveDateFrom<seq2seq4repair_space><=<seq2seq4repair_space>:effectiveDateFrom<seq2seq4repair_space>and<seq2seq4repair_space>(s.effectiveDateTo<seq2seq4repair_space>is<seq2seq4repair_space>null<seq2seq4repair_space>or<seq2seq4repair_space>s.effectiveDateTo<seq2seq4repair_space>>=<seq2seq4repair_space>:effectiveDateFrom))" ) . append ( ")" ) ;