Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring data method name for enum

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?

like image 355
alizelzele Avatar asked May 25 '15 05:05

alizelzele


1 Answers

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);
like image 80
Snekse Avatar answered Oct 09 '22 01:10

Snekse