Skip to content
Advertisement

Querying using class in Spring

i’m trying to do this query

List<Product> findProductByCategory_CategoryNameAndPriceBetween(String category, double min, double max);

but the return of the query is an empty list. What am I doing wrong? I also tried without the underscore between Category and Category Name. This are the class category and product:

JavaScript
JavaScript

And this is how I have implemented the repository:

JavaScript

Advertisement

Answer

With the implementation below, your query is doing just fine.

Please note that I’ve added an alternative implementation:

JavaScript

I suspect that when you are testing this, you are not saving any products because your code is missing cascading inside Category class. Hence, I’ve added my implementation used during tests.

Category class

JavaScript

Product class

JavaScript

ProductDao

JavaScript

Let’s add a couple of tests about this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement