I inherited this class what I am trying to do is:
1) create a Set of SelectItem (works)
2) query the database for records (works)
3) grab the column from the recordset call attribute2 (works)
4) if the attribute satisfies three condiitions (works)
5) add it to the Set showSet (doesn't work correctly).
What I am seeing is the elements to be added to the Set showSet are coming back as references to memory locations and as each is distinct they all get added to the Set. What I need to do (and can't figure out) is how to insert elements into the Set as values so that there is no duplication. 4 values are returned with one repeat.
Looking forward to your guidance.
public List<SelectItem> getActiveAttr2Vals(int industrycode, String polymerVal, String techVal, String firstAttrib){ Set<SelectItem> showSet = new HashSet<SelectItem>(); try{ Query qrya2 = em.createQuery("select distinct p from Profile p where p.industryType = ?1 and lower(p.polymer) = ?2 " + "and lower(p.technology) = ?3 and lower(p.attribute1) = ?4 and p.statusFlag = 'Active'"); qrya2.setParameter(1, industrycode); qrya2.setParameter(2, polymerVal.toLowerCase()); qrya2.setParameter(3, techVal.toLowerCase()); qrya2.setParameter(4, firstAttrib.toLowerCase()); List<Profile> tableList = qrya2.getResultList(); //problematic part for (Profile profile : tableList) { SelectItem attr2Item = new SelectItem(profile.getAttribute2()); if(profile.getAttribute2Label() != null && profile.getAttribute2() != null && !profile.getAttribute2().equalsIgnoreCase("")){ showSet.add(attr2Item); //end problematic part }else{ System.out.println("Attribute2 is NULL & hence not added..."); } } }catch (Exception e) { e.printStackTrace(); } return showSet; }