3

I'm developing an application and I tried to upgrade from spring boot 1.5.4 to 2.0.0 but I have one issue with my repositories interfaces, in example:

package com.acu.repositories.it;

import com.acu.model.it.User;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends JpaRepository<User, Integer> {

List<User> findByName(String name);

User findById(Integer id);

}

It compiles ok and works fine with spring boot 1.5.4 but I'm having the following issue when I try to compile with 2.0.0 version:

com/acu/services/it/UserService.java:[52,30] error: incompatible types: Integer cannot be converted to User com/acu/repositories/it/UserRepository.java:[13,9] error: findById(Integer) in UserRepository clashes with findById(ID) in CrudRepository

ID extends Object declared in interface CrudRepository
T extends Object declared in interface CrudRepository

any idea?

Thanks.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Esteban
  • 59
  • 1
  • 9
  • This isn't spring boot, it's spring data jpa. – Software Engineer Jul 14 '17 at 02:20
  • 3
    And I think the default method to find by id is called `fineOne(ID id)`, so you should remove your `findById(Integer id)` method anyway. – Software Engineer Jul 14 '17 at 02:23
  • 1
    The error message is pretty straightforward. Remove the `findById` method because you don't need it. – Abhijit Sarkar Jul 14 '17 at 02:25
  • Yes, it works! I removed all findById methods from my repositories. – Esteban Jul 14 '17 at 03:03
  • 4
    You are also aware that Spring Boot 2 is still in a milestone release, using nightly builds of dependent projects. In other words it isn't production ready yet.. One of the changes in Spring Data is that all `findOne` related operations are now using `*byId` so instead of `findOne` it is now named `findById` and `deleteById` etc. – M. Deinum Jul 14 '17 at 05:38
  • Thanks! Yes, I had implemented a findById in each repository and now I just remove them and replace every delete by deleteById. – Esteban Jul 14 '17 at 13:48

1 Answers1

4

You can use getOne(ID) each time the new repository changes.

kiyah
  • 1,502
  • 2
  • 18
  • 27
srikanth
  • 61
  • 6