I am trying to return a arraylist of POJO. When I debug, I see the the arraylist of pojo is 4 and I can see the entries but it returns only the last entry and prints it four times. Not sure where I am wrong.
Expected: aId - 123 aId - 234 aId - 456 aId - 678
Actual
aId - 678 aId - 678 aId - 678 aId - 678 UPDATED< initializing E inside the loop solved the problem
@Override
public List<E> findAllByLoginId(String loginId) {
String oracleUrl = oracleProperties.getUrl();
List<E> el = new ArrayList<>();
int page =0;
int totalPages = 1;
URL url;
try {
for(page=0;page<totalPages;page++){
url = new URL(oracleUrl+loginId+"/page/" + page");
ObjectMapper mapper = new ObjectMapper();
UContent value = mapper.readValue(url, UContent.class);
List<UEntitiy> entities = value.getContent();
totalPages = value.getTotalPages();
total = value.getTotalElemenets();
if (entities!=null){
String query = null;
for(UEntitiy item : entities){
item = droolsHelper.createQueryWithDrools(item); // Drools
if(!StringUtils.isEmpty(item.getCQuery()) && item.getCQuery()!=null){
result = runNeo4j(item.getCQuery());// execute in neo4j
if(result.list().size() == 0){
E e = new E();
e.setCId(cId);
e.setR(r);
e.setU(uId);
el.add(e);
}
}
}
}
}
}
catch (MalformedURLException e) {
e.printStackTrace();
} catch (JsonParseException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return el;
}