0

I have the following entity structure:

public class Car {

    private String make;
    private Integer price;
    private Integer year;
}

I want to search for all cars made by HONDA whose price is higher than 50,000 or made in 2019.

The query I need to come up with is as follows:

SELECT * FROM car WHERE make='HONDA' AND (price>50000 OR year=2019);

I tried the following method but it produces the query without the brackets and hence producing the incorrect results.

List<Car> findAllByMakeAndPriceGreaterThanOrMake(String make, Integer price, Integer year);

Alternatively, I can use @Query to write my own query but wanted to see if there's an existing way to achieve my requirement.

Manoj Shrestha
  • 4,246
  • 5
  • 47
  • 67
  • 1
    Possible duplicate of [Spring data jpa - How to combine multiple And and Or through method name](https://stackoverflow.com/questions/35788856/spring-data-jpa-how-to-combine-multiple-and-and-or-through-method-name) – Jens Schauder Jun 24 '19 at 05:05

1 Answers1

0

Try this one:

List<Car> findByMakeAndPriceGreaterThanOrYear(String make,Integer price, Integer year)
Sana
  • 360
  • 3
  • 13