If you look at the SimpleJpaRepository
which is a common implementation of the CrudRepository
you can see that it will simply invoke save for each of the elements:
@Transactional
public <S extends T> List<S> saveAll(Iterable<S> entities) {
Assert.notNull(entities, "The given Iterable of entities not be null!");
List<S> result = new ArrayList<S>();
for (S entity : entities) {
result.add(save(entity));
}
return result;
}
The save itself distinguishes itself whether to persist
or merge
the given entity:
@Transactional
public <S extends T> S save(S entity) {
if (entityInformation.isNew(entity)) {
em.persist(entity);
return entity;
} else {
return em.merge(entity);
}
}
So to answer your question.. yes you can mix both new and existing entities in the passes list.