Search code examples
javamysqlspring-bootrepository

Repository method findById with underscore Spring Boot


In entity class Flights I have fields private City flight_from and private City flight_to and I need repository method to return flights by id of flight_from. I am trying to do like this:

List<Flights> findByFlight_toId(Integer id);

I have tried findByFlightToId, findByFlight_to_id, findByFlight__toId with double underscore and other, still can't find it. Is there any solution for that?


Solution

  • spring-data treats the underscore as a special character, see this.

    Your best solution is to follow the naming conventions and rename your variables flightTo and flightFrom.