Can I use enum parameter into JpaRepository nativeQuery?

前端 未结 4 951
温柔的废话
温柔的废话 2020-12-30 00:44

Entity looks like this:

@Getter
@Setter
@Entity
public class Application {
@Id
private Long id;
@Enumerated(EnumType.STRING)
private ApplicationStatus status         


        
4条回答
  •  萌比男神i
    2020-12-30 01:39

    To extend @Aivaras answer: If you want to use list of statuses, SpEL ecpression is slightly different - you need to do projection:

    public interface ApplicationRepository extends JpaRepository {
        @Query(nativeQuery = true, value = "SELECT app FROM #{#entityName} AS app WHERE app.status in :#{#statuses.![name()]}")
        List find(@Param("statuses") List statuses);
    }
    

    Note the change of expression to

    #{#statuses.![name()]}
    

提交回复
热议问题