简体   繁体   中英

Spring-Data @Query with Collection params

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.

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())")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM