Reputation: 5524
Below is my repository method
List<Shipment> findByProductCategoriesBetweenQuarter( Set<Category> categories, Quarter from, Quarter to)
where Category is an Entity and Quarter is @Embeddable as below
class Quarter {
int year;
Quarters q; //Enum
}
I would like to create a custom Repository impl with @Query with a below representational query
@Query("select s from Shipment s where Category in (categories) and Quarter between (from, to)")
Looks like @Query
works pretty well with primitives, couldn't find an example which could help me implement the case above.
so couple of question here 1. Is it possible at all 2. If possible, requesting some reference.
PS: Cant do QueryDSL now.
Upvotes: 3
Views: 525
Reputation: 21883
JPA will store Enum
ordinal as int
in the database tables.
So you can do the following.
@Query("select s from Shipment s where Category in (categories) and Quarter between (from.ordinal(), to.ordinal())")
Upvotes: 3