简体   繁体   中英

Spring Data JPA save list entity return list in same the order?

Does the method in Spring-Data-JPA's CrudRepository

 <S extends T> Iterable<S> saveAll(Iterable<S> entities)

return list in the same order ?

In that version an actual List is the return type:

@Transactional
public <S extends T> List<S> save(Iterable<S> entities) {

    List<S> result = new ArrayList<S>();

    if (entities == null) {
        return result;
    }

    for (S entity : entities) {
        result.add(save(entity));
    }

    return result;
}

so if you pass a List to the method, you will get the result in the exact same order as the ArrayList is the implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM