0
`  for(int i=0;i<units.size();i++){
        obj = units.get(i);
        proMap =  (LinkedHashMap)obj;
        myProject.setUsername((String) proMap.get("username"));
        myProject.setProjectName((String) proMap.get("projectName"));
        myProject.setProjectDesc((String) proMap.get("projectDesc"));
        projectList.add(myProject);
    }
    itrackJpaRepository.saveAll(projectList);

`

Only the last object is getting saved.

from the log, i can see that only once the sequence is retrieved.Hence all objects are updated with the same sequence. select next_val as id_val from hibernate_sequence for update

please help

aki
  • 1
  • 1
  • Please show some code how you create the objects how your entites look like. do you have equals implemented? – Simon Martinelli Jan 01 '20 at 11:31
  • You have N references to a single, unique object in your list. There must be a `new MyProject()` *inside* the loop. – JB Nizet Jan 01 '20 at 11:45
  • I can't close anymore, but this is a duplicate of https://stackoverflow.com/questions/19843506/why-does-my-arraylist-contain-n-copies-of-the-last-item-added-to-the-list – JB Nizet Jan 01 '20 at 11:47
  • Thanks a lot. resolved by adding new MyProject(). – aki Jan 01 '20 at 12:07
  • Can you please provide your solution as the answer? Otherwise the question will show up as unanswered. Thank you – Simon Martinelli Jan 02 '20 at 10:04

0 Answers0