2

I have a Contest entity:

@Entity
@Table(name = "T_CONTEST")
public class Contest { 

    //rest of the attributes

    @Column(name = "START_TIME")
    private LocalDateTime start;

    @Column
    @Enumerated(EnumType.STRING)
    private ContestStatus status;
}

I want to get the first contest with most recent start time AND status=PENDING. I know this can be done using a custom query, but what is the correct Spring JPA method to do this? I tried following but it's incorrect.

Contest findTopByOrderByStartAndStatusDesc(ContestStatus status);
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
Maddy
  • 2,114
  • 7
  • 30
  • 50
  • The question that this is marked a duplicate of is not the same. The answer to that question is the same solution, but the question itself is quite different. The accepted answer here is correct, clear, and simple to understand. – E-Riz Dec 17 '21 at 14:09

1 Answers1

14

Did you try

findTopByContestStatusOrderByStartDesc(ContestStatus status)

?

Kloker
  • 499
  • 4
  • 14