C
C
Chvalov2018-10-20 06:10:43
Hibernate
Chvalov, 2018-10-20 06:10:43

What about findOne when migrating code from Spring Boot 1.5.X to 2.X?

After switching from Spring Boot 1.5.X to version 2.X , errors rained down:

"Inferred type 'S' for type parameter 'S' is not within its bound; should extend 'ua.com.philmo.backend.entity.ProjectEntity".

My code: ⏬⬇️⏬
GeneralDao.java
public interface GeneralDao<T> {
    T getById(Long id);     // получение объекта по id
}
ProjectDao.java
public interface ProjectDao extends GeneralDao<ProjectEntity> {
}
ProjectRepository.java
@Repository
public interface ProjectRepository extends JpaRepository<ProjectEntity, Long> {
}
ProjectService.java
@Service
public class ProjectService implements ProjectDao {

    private final ProjectRepository projectRepository;

    @Autowired
    public ProjectService(ProjectRepository projectRepository) {
        this.projectRepository = projectRepository;
    }

    @Override
    public ProjectEntity getById(Long id) {
        return projectRepository.findOne(id); // <-- ПРОБЛЕМНОЕ МЕСТО !!!!
    }

}
♿️How to treat?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question