I'am tring to retrieve from my database (using JPA) for a given list of items name their id, my function wich called by my addFunction return just the id of the last item and ignore the rest!
public ArrayList<Integer> getListidItemByItemName()
{
try{
EntityTransaction entityTrans=emm.getTransaction();
entityTrans.begin();
for (String val : listItem)
{
System.out.println("my values"+val);
javax.persistence.Query multipleSelect= em.createQuery("SELECT i.ItemId FROM Item i WHERE i.ItemName IN (:w)" );
multipleSelect.setParameter("w", val);
List ItemId = new LinkedList();
ItemId= multipleSelect.getResultList();
listIdItem = new ArrayList(ItemId);
}
entityTrans.commit();
System.out.println("Id for given item name"+listIdItem);
return listIdItem;
}
catch(Exception e)
{
e.printStackTrace();
}
The result :
INFO: my valuesResponse Time
INFO: my valuesAssigned Group Response Time
INFO: Id for given item name[7] //the id of the last item in the list
return listIdItem;
}
Where is the problem?
UPDATE: I have use the solution of mat and it worked fine
thank you