spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

add saveAll into repository interface [DATAJDBC-552]

Open spring-projects-issues opened this issue 5 years ago • 4 comments
trafficstars

benzen opened DATAJDBC-552 and commented

Having the following 

 

@Component
 public interface ProjectRepository extends CrudRepository<Project, Long>

{ List<Project> findByIdIn(List<Long> ids); List<Project> findByIsArchived(Boolean isArchived); List<Project> findByIsArchivedAndClientId(Boolean isArchived, Long clientId); List<Project> saveAll(List<Project> project); }

 

Compiler doesn't complain, but at runtime  it seams that i can't select List as a return type for save all.

I'm using spring data jdbc throught spring boot 2.3.0.RELEASE

Here is my error

Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List ca.code3.timekeeper.repository.ProjectRepository.saveAll(java.util.List)! Reason: No property saveAll found for type Project!

Hope this help


No further details from DATAJDBC-552

spring-projects-issues avatar May 23 '20 00:05 spring-projects-issues

Mark Paluch commented

saveAll is defined on CrudRepository. Care to elaborate on why you cannot use that one?

Right now, we do not declare a JdbcRepository interface as there was no need to do so

spring-projects-issues avatar May 28 '20 12:05 spring-projects-issues

benzen commented

Sure, i did'nt want to use that one because of the return type. The default one return an Iterable, I prefer using a List in order to call stream on it.

 

Maybe it's just a documentation issue, but I was expecting to be able to declare saveAll with a return type in the list of legal one

spring-projects-issues avatar May 28 '20 12:05 spring-projects-issues

Dimo Velev commented

benzen I guess you know that you can easily convert to stream using https://docs.oracle.com/javase/8/docs/api/java/util/stream/StreamSupport.html - I did that in a default interface method on the repo for the cases where I need stream. It is a bit of a pain but I can live with it

spring-projects-issues avatar May 29 '20 12:05 spring-projects-issues

benzen commented

I ended up making a list and maping through it, calling save and returning a list of save entity. One or the other is fine by me.

My problem is more that it's note clear that save* methods can't be redeclared just like the finder can be

spring-projects-issues avatar May 29 '20 19:05 spring-projects-issues