Source:
<code>public Set<String> retrieveServiceLevelsForOwner(Owner owner, boolean exempt) { String stmt = "SELECT DISTINCT Attribute.name, Attribute.value, Product.id " + "FROM Pool AS Pool " + " INNER JOIN Pool.product AS Product " + <START> " INNER JOIN Product.attributes AS Attribute " + <END> " LEFT JOIN Pool.entitlements AS Entitlement " + "WHERE Pool.owner.id = :owner_id " + " AND (Attribute.name = 'support_level' OR Attribute.name = 'support_level_exempt') " + " AND (Pool.endDate >= current_date() OR Entitlement.endDateOverride >= current_date()) " + " ORDER BY Attribute.name DESC"; Query q = currentSession().createQuery(stmt); q.setParameter("owner_id", owner.getId()); List<Object[]> results = q.list(); Set<String> slaSet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); Set<String> exemptSlaSet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); Set<String> exemptProductIds = new HashSet<String>(); for (Object[] result : results) { String name = (String) result[0]; String value = (String) result[1]; String productId = (String) result[2]; if ("support_level_exempt".equals(name) && "true".equalsIgnoreCase(value)) { exemptProductIds.add(productId); } else if ("support_level".equalsIgnoreCase(name) && (value != null && !value.trim().equals("")) && exemptProductIds.contains(productId)) { exemptSlaSet.add(value); } } for (Object[] result : results) { String name = (String) result[0]; String value = (String) result[1]; if (!"support_level_exempt".equals(name) && !exemptSlaSet.contains(value)) { slaSet.add(value); } } if (exempt) { return exemptSlaSet; } return slaSet; }</code><technical_language>name aliases small case -"attribute" instead of "Attribute"</technical_language>

Target:
public Set<String> retrieveServiceLevelsForOwner(Owner owner, boolean exempt) { String stmt = "SELECT DISTINCT attribute.name, attribute.value, product.id " + "FROM Pool AS pool " + " INNER JOIN Pool.product AS product " + " INNER JOIN Product.attributes AS attribute " + " LEFT JOIN Pool.entitlements AS entitlement " + "WHERE pool.owner.id = :owner_id " + " AND (attribute.name = 'support_level' OR attribute.name = 'support_level_exempt') " + " AND (pool.endDate >= current_date() OR entitlement.endDateOverride >= current_date()) " + "ORDER BY attribute.name DESC"; Query q = currentSession().createQuery(stmt); q.setParameter("owner_id", owner.getId()); List<Object[]> results = q.list(); Set<String> slaSet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); Set<String> exemptSlaSet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); Set<String> exemptProductIds = new HashSet<String>(); for (Object[] result : results) { String name = (String) result[0]; String value = (String) result[1]; String productId = (String) result[2]; if ("support_level_exempt".equals(name) && "true".equalsIgnoreCase(value)) { exemptProductIds.add(productId); } else if ("support_level".equalsIgnoreCase(name) && (value != null && !value.trim().equals("")) && exemptProductIds.contains(productId)) { exemptSlaSet.add(value); } } for (Object[] result : results) { String name = (String) result[0]; String value = (String) result[1]; if (!"support_level_exempt".equals(name) && !exemptSlaSet.contains(value)) { slaSet.add(value); } } if (exempt) { return exemptSlaSet; } return slaSet; }