Buggy code:
public class DriftTemplateMapDatabaseUpgradeTask implements DatabaseUpgradeTask { private static final Logger LOG = DbUtilsI18NFactory . getLogger ( DriftPathDirectoryDatabaseUpgradeTask . class ) ; public void execute ( DatabaseType databaseType , Connection connection ) throws SQLException { String sql = ( ( ( ( ( ( ( ( ( ( ( ( ( ( "" + ( ( ( ( ( ( ( ( "<seq2seq4repair_space>insert<seq2seq4repair_space>into<seq2seq4repair_space>RHQ_DRIFT_DEF_TEMPLATE<seq2seq4repair_space>(" + "<seq2seq4repair_space>ID," ) + "<seq2seq4repair_space>RESOURCE_TYPE_ID," ) + "<seq2seq4repair_space>CONFIG_ID," ) + "<seq2seq4repair_space>NAME," ) + "<seq2seq4repair_space>DESCRIPTION," ) + "<seq2seq4repair_space>IS_USER_DEFINED," ) + "<seq2seq4repair_space>CTIME<seq2seq4repair_space>)" ) + "<seq2seq4repair_space>select<seq2seq4repair_space>" ) ) + ( databaseType . getSequenceInsertValue ( connection , "RHQ_DRIFT_DEF_TEMPLATE_ID_SEQ" ) ) ) + "," ) + "<seq2seq4repair_space>tm.RESOURCE_TYPE_ID,<seq2seq4repair_space>" ) + "<seq2seq4repair_space>ct.CONFIG_ID,<seq2seq4repair_space>" ) + "<seq2seq4repair_space>ct.NAME,<seq2seq4repair_space>" ) + "<seq2seq4repair_space>ct.DESCRIPTION,<seq2seq4repair_space>" ) + "<seq2seq4repair_space>" ) + ( databaseType . getBooleanValue ( false ) ) ) + "," ) + "<seq2seq4repair_space>" ) + ( System . currentTimeMillis ( ) ) ) + "<seq2seq4repair_space>from<seq2seq4repair_space>RHQ_DRIFT_TEMPLATE_MAP<seq2seq4repair_space>tm<seq2seq4repair_space>" ) + "<seq2seq4repair_space>join<seq2seq4repair_space>RHQ_RESOURCE_TYPE<seq2seq4repair_space>rt<seq2seq4repair_space>on<seq2seq4repair_space>tm.RESOURCE_TYPE_ID<seq2seq4repair_space>=<seq2seq4repair_space>rt.ID" ) + "<seq2seq4repair_space>join<seq2seq4repair_space>RHQ_CONFIG_TEMPLATE<seq2seq4repair_space>ct<seq2seq4repair_space>on<seq2seq4repair_space>tm.CONFIG_TEMPLATE_ID<seq2seq4repair_space>=<seq2seq4repair_space>ct.ID" ; DriftTemplateMapDatabaseUpgradeTask . LOG . debug ( EXECUTING_SQL , sql ) ; databaseType . executeSql ( connection , sql ) ; <START_BUG> sql = "" + ( ( ( ( ( ( ( "<seq2seq4repair_space>update<seq2seq4repair_space>RHQ_DRIFT_DEFINITION<seq2seq4repair_space>dd<seq2seq4repair_space>set<seq2seq4repair_space>DRIFT_DEF_TEMPLATE_ID<seq2seq4repair_space>=" + "<seq2seq4repair_space>(<seq2seq4repair_space>select<seq2seq4repair_space>dt.ID" ) + "<seq2seq4repair_space>from<seq2seq4repair_space>RHQ_DRIFT_DEF_TEMPLATE<seq2seq4repair_space>dt" ) + "<seq2seq4repair_space>join<seq2seq4repair_space>RHQ_RESOURCE_TYPE<seq2seq4repair_space>rt<seq2seq4repair_space>on<seq2seq4repair_space>dt.RESOURCE_TYPE_ID<seq2seq4repair_space>=<seq2seq4repair_space>rt.ID" ) + "<seq2seq4repair_space>join<seq2seq4repair_space>RHQ_RESOURCE<seq2seq4repair_space>res<seq2seq4repair_space>on<seq2seq4repair_space>rt.ID<seq2seq4repair_space>=<seq2seq4repair_space>res.RESOURCE_TYPE_ID" ) + "<seq2seq4repair_space>and<seq2seq4repair_space>dd.RESOURCE_ID<seq2seq4repair_space>=<seq2seq4repair_space>res.ID" ) + "<seq2seq4repair_space>)" ) + "<seq2seq4repair_space>where<seq2seq4repair_space>dd.DRIFT_DEF_TEMPLATE_ID<seq2seq4repair_space>is<seq2seq4repair_space>null" ) ; <END_BUG> DriftTemplateMapDatabaseUpgradeTask . LOG . debug ( EXECUTING_SQL , sql ) ; databaseType . executeSql ( connection , sql ) ; sql = "select<seq2seq4repair_space>cs.ID<seq2seq4repair_space>from<seq2seq4repair_space>RHQ_DRIFT_CHANGE_SET<seq2seq4repair_space>cs<seq2seq4repair_space>where<seq2seq4repair_space>cs.VERSION<seq2seq4repair_space>=<seq2seq4repair_space>0" ; DriftTemplateMapDatabaseUpgradeTask . LOG . debug ( EXECUTING_SQL , sql ) ; List < Object [ ] > rows = databaseType . executeSelectSql ( connection , sql ) ; sql = ( "insert<seq2seq4repair_space>into<seq2seq4repair_space>RHQ_DRIFT_SET<seq2seq4repair_space>(<seq2seq4repair_space>ID<seq2seq4repair_space>)<seq2seq4repair_space>values<seq2seq4repair_space>(<seq2seq4repair_space>" + ( databaseType . getSequenceInsertValue ( connection , "RHQ_DRIFT_SET_ID_SEQ" ) ) ) + "<seq2seq4repair_space>)" ; for ( Object [ ] row : rows ) { int csId = ( ( Number ) ( row [ 0 ] ) ) . intValue ( ) ; DriftTemplateMapDatabaseUpgradeTask . LOG . debug ( EXECUTING_SQL , sql ) ; databaseType . executeSql ( connection , sql ) ; int setId = databaseType . getSequenceValue ( connection , "RHQ_DRIFT_SET" , "ID" ) ; String updateSql = ( ( "update<seq2seq4repair_space>RHQ_DRIFT<seq2seq4repair_space>set<seq2seq4repair_space>DRIFT_SET_ID<seq2seq4repair_space>=<seq2seq4repair_space>" + setId ) + "<seq2seq4repair_space>where<seq2seq4repair_space>DRIFT_CHANGE_SET_ID<seq2seq4repair_space>=<seq2seq4repair_space>" ) + csId ; DriftTemplateMapDatabaseUpgradeTask . LOG . debug ( EXECUTING_SQL , updateSql ) ; databaseType . executeSql ( connection , updateSql ) ; updateSql = ( ( "update<seq2seq4repair_space>RHQ_DRIFT_CHANGE_SET<seq2seq4repair_space>set<seq2seq4repair_space>DRIFT_SET_ID<seq2seq4repair_space>=<seq2seq4repair_space>" + setId ) + "<seq2seq4repair_space>where<seq2seq4repair_space>ID<seq2seq4repair_space>=<seq2seq4repair_space>" ) + csId ; DriftTemplateMapDatabaseUpgradeTask . LOG . debug ( EXECUTING_SQL , updateSql ) ; databaseType . executeSql ( connection , updateSql ) ; } } }

Fix:
sql = "" + ( ( ( ( ( ( ( "<seq2seq4repair_space>update<seq2seq4repair_space>RHQ_DRIFT_DEFINITION<seq2seq4repair_space>dd<seq2seq4repair_space>set<seq2seq4repair_space>DRIFT_DEF_TEMPLATE_ID<seq2seq4repair_space>=" + "<seq2seq4repair_space>(<seq2seq4repair_space>select<seq2seq4repair_space>dt.ID" ) + "<seq2seq4repair_space>from<seq2seq4repair_space>RHQ_DRIFT_DEF_TEMPLATE<seq2seq4repair_space>dt" ) + "<seq2seq4repair_space>join<seq2seq4repair_space>RHQ_RESOURCE_TYPE<seq2seq4repair_space>rt<seq2seq4repair_space>on<seq2seq4repair_space>dt.RESOURCE_TYPE_ID<seq2seq4repair_space>=<seq2seq4repair_space>rt.ID" ) + "<seq2seq4repair_space>join<seq2seq4repair_space>RHQ_RESOURCE<seq2seq4repair_space>res<seq2seq4repair_space>on<seq2seq4repair_space>rt.ID<seq2seq4repair_space>=<seq2seq4repair_space>res.RESOURCE_TYPE_ID" ) + "<seq2seq4repair_space>where<seq2seq4repair_space>dd.RESOURCE_ID<seq2seq4repair_space>=<seq2seq4repair_space>res.ID" ) + "<seq2seq4repair_space>)" ) + "<seq2seq4repair_space>where<seq2seq4repair_space>dd.DRIFT_DEF_TEMPLATE_ID<seq2seq4repair_space>is<seq2seq4repair_space>null" ) ;