Is there any way to put enum value in method name with Spring Data? It can be done with @Query annotaion with something like this:
  @Query("select t from Ticket as t where t.status != desk.enums.TicketStatus.CLOSED")
  List<Ticket> findActiveTickets();
where status is the enum. But how can it be done with only using method names? Using something like List<Ticket> findByStatusIsNotClosed(); will cause No property isNotClosed found for type TicketStatus.
So how can it be done without using @Query?
If you're using Java 8, you can use the default keyword in the interface to delegate to a more generic method. 
default List<Ticket> findActiveTickets() {
    return findByTicketStatusNotIn(ImmutableList.of(TicketStatus.CLOSED));
}
List<Ticket> findByTicketStatusNotIn(List<TicketStatus> status);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With