简体   繁体   中英

Need to inherit jpa and spanner interfaces to a common interface

// Interface 1:

@Repository
public interface EmpSpannerrepo extends SpannerRepository<Emp,Integer>{
}

// Interface 2:

@Repository
 public interface EmpPsqlrepo extends JpaRepository<Emp,Integer>{
 }

// Transfering emp details to Psql server and Spanner

public void insertEmpSpannerDetails(List<Emp> emps,int batchSize) throws SQLException, InterruptedException{
    common.insert(emps,batchSize,Object);
}

public void insertEmpPsqlDetails(List<Emp> emps,int batchSize) throws SQLException, InterruptedException{
        common.insert(emps,batchSize,Object);
    }

Need this object to determine at runtime where to push the code either to spanner or PSql Insert function is exactly same in both cases so rather than writing the same code again, how can i do that with a common code?

// What have i tried? Tried extending both interfaces to a common one and then using that to save the list, but again it gives me error saying SpannerRepoFactory does not support Query by Example.

Any hints are appreciated.

Any interface that extends Spring Cloud GCP's SpannerRepository will have a concrete instance created for you at runtime. Spring Data JPA will do the same for its interfaces. Since Spring Cloud GCP's Spring Data Spanner implementation is not a JPA implementation, it's not valid for a repository interface to extend both, SpannerRepository and a JPA repository.

In this case, you'll have to write a common layer to invoke correct methods in each repository. By the way, SpannerRepository does not have an insert() method; it has save() .

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