Source:
<code>public List<TransactionReportRow> getTransactionDetailsForLot(final Integer lotId) { final List<TransactionReportRow> transactions = new ArrayList<>(); try { final String sql = "SELECT i.userid,i.lotid,i.trndate," <START> + "(CASE WHEN trnstat = 0 THEN '" + TransactionStatus.PENDING.getValue() <END> + "' WHEN trnstat = 1 THEN '" + TransactionStatus.CONFIRMED.getValue() + "' WHEN trnstat = 2 THEN '" + TransactionStatus.CANCELLED.getValue() + "' END) as trnStatus, " + " i.trnqty,i.sourceid,l.listname, i.comments," + "(CASE WHEN trntype = 0 THEN '" + TransactionType.DEPOSIT.getValue() + "' WHEN trntype = 1 THEN '" + TransactionType.WITHDRAWAL.getValue() + "' WHEN trntype = 2 THEN '" + TransactionType.DISCARD.getValue() + "' WHEN trntype = 3 THEN '" + TransactionType.ADJUSTMENT.getValue() + "' END) as trntype " + "FROM ims_transaction i LEFT JOIN listnms l ON l.listid = i.sourceid " + " INNER JOIN ims_lot lot ON lot.lotid = i.lotid " + "WHERE i.lotid = :lotId AND i.trnstat <> 9 ORDER BY i.trnid"; final Query query = this.getSession().createSQLQuery(sql); query.setParameter("lotId", lotId); this.createTransactionRow(transactions, query); } catch (final Exception e) { final String message = "Error with ggetTransactionDetailsForLot(" + lotId + ") query from Transaction: " + e.getMessage(); LOG.error(message, e); throw new MiddlewareQueryException(message, e); } return transactions; }</code><technical_language>Fix this query (9 instead of 2 for Cancelled). Please ids in enum TransactionStatus enum instead of hardcoded value.s</technical_language>

Target:
public List<TransactionReportRow> getTransactionDetailsForLot(final Integer lotId) { final List<TransactionReportRow> transactions = new ArrayList<>(); try { final String sql = "SELECT i.userid,i.lotid,i.trndate," + "(CASE WHEN trnstat = " + TransactionStatus.PENDING.getIntValue() + " THEN '" + TransactionStatus.PENDING.getValue() + "' WHEN trnstat = " + TransactionStatus.CONFIRMED.getIntValue() + " THEN '" + TransactionStatus.CONFIRMED.getValue() + "' WHEN trnstat = " + TransactionStatus.CANCELLED.getIntValue() + " THEN '" + TransactionStatus.CANCELLED.getValue() + "' END) as trnStatus, " + " i.trnqty,i.sourceid,l.listname, i.comments," + "(CASE WHEN trntype = " + TransactionType.DEPOSIT.getId() + " THEN '" + TransactionType.DEPOSIT.getValue() + "' WHEN trntype = " + TransactionType.WITHDRAWAL.getId() + " THEN '" + TransactionType.WITHDRAWAL.getValue() + "' WHEN trntype = " + TransactionType.DISCARD.getId() + " THEN '" + TransactionType.DISCARD.getValue() + "' WHEN trntype = " + TransactionType.ADJUSTMENT.getId() + " THEN '" + TransactionType.ADJUSTMENT.getValue() + "' END) as trntype " + "FROM ims_transaction i LEFT JOIN listnms l ON l.listid = i.sourceid " + " INNER JOIN ims_lot lot ON lot.lotid = i.lotid " + "WHERE i.lotid = :lotId ORDER BY i.trnid"; final Query query = this.getSession().createSQLQuery(sql); query.setParameter("lotId", lotId); this.createTransactionRow(transactions, query); } catch (final Exception e) { final String message = "Error with ggetTransactionDetailsForLot(" + lotId + ") query from Transaction: " + e.getMessage(); LOG.error(message, e); throw new MiddlewareQueryException(message, e); } return transactions; }