2017-08-09 40 views
2

我上在下面的代碼的findOne呼叫得到一個argument mismatch; Long cannot be converted to Example<S>入門`龍不能被轉化成實施例<S>`春季5 JPA findOne()

public Optional<AuditEvent> find(Long id) { 
    return Optional.ofNullable(persistenceAuditEventRepository.findOne(id)) 
     .map(auditEventConverter::convertToAuditEvent); 
} 

上面的代碼被轉換爲彈簧5和Spring Boot 2.它在最初的Spring 4和Spring Boot 1應用程序中運行良好。

任何想法,我需要將上面的代碼轉換爲?

回答

2

由於彈簧5的一部分和Spring數據JPA 2.0.0.M3,我可以看到findOne方法CrudRepository被刪除到一個在QueryByExampleExecutor 所以最好更改爲Optional<T> findById(ID arg0);,而不是findOne方法 請在下面找到:

@NoRepositoryBean 
public interface CrudRepository<T, ID> extends Repository<T, ID> { 
    <S extends T> S save(S arg0); 

    <S extends T> Iterable<S> saveAll(Iterable<S> arg0); 

    Optional<T> findById(ID arg0); 

    boolean existsById(ID arg0); 

    Iterable<T> findAll(); 

    Iterable<T> findAllById(Iterable<ID> arg0); 

    long count(); 

    void deleteById(ID arg0); 

    void delete(T arg0); 

    void deleteAll(Iterable<? extends T> arg0); 

    void deleteAll(); 
} 

QueryByExampleExecutor

public abstract interface QueryByExampleExecutor<T> { 
    public abstract <S extends T> S findOne(Example<S> paramExample); 

    public abstract <S extends T> Iterable<S> findAll(Example<S> paramExample); 

    public abstract <S extends T> Iterable<S> findAll(Example<S> paramExample, Sort paramSort); 

    public abstract <S extends T> Page<S> findAll(Example<S> paramExample, Pageable paramPageable); 

    public abstract <S extends T> long count(Example<S> paramExample); 

    public abstract <S extends T> boolean exists(Example<S> paramExample); 
} 

檢查QueryForExampleExecutor文檔:

https://docs.spring.io/spring-data/jpa/docs/2.0.0.RC2/reference/html/