I wanted to persist a list of entities using JPA. My first approach was as follows:
List<myEntity>entityList=myService.getMyEntities();`
\\some other activities...`
entityList.parallelStream().forEach(l->l.setMyStatus(MyStatus.newStatus);
entityList.parallelStream().forEach(l->myService.getEntityManager().merge(l));
But I got an OptimisticLockException.
My second approach was using streams instead of parallel streams.
entityList.stream().forEach(l->myService.getEntityManager().merge(l));
The second approach works! Now my question is why parallelStream() cause optimistic locking exceptions ?