2

I have a LOCATION entity and it contains COUNTRY, STATE and CITY. And I have a LocationRepository interface defined as:

public interface SpringDataLocationRepository extends LocationRepository,
        Repository<Location, Integer> {
}

I want to find all the state by country. I can follow the method name standard to query everything for LOCATION entity. If I want List, do I need to create StateRepository interface and query everything about STATE in there? If I can just get it from LocationRepository, what's the method looks like? I assume it will look something like below (of course it doesn't work).

List findStateByCountryCountryId(Integer id) throws DataAccessException;

1 Answer 1

4

Below method should work:

List<Location> findByCountryId(Integer id)

Then you can get state from the Location objects in the list.

PS: Of course, this is not tested/executed by me.

Sign up to request clarification or add additional context in comments.

1 Comment

this related question/answer more thoroughly explains this situation - stackoverflow.com/questions/24441411/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.