Random select rows via JPA

后端 未结 2 485
闹比i
闹比i 2020-12-16 17:35

In Mysql,

SELECT id FROM table ORDER BY RANDOM() LIMIT 5

this sql can select 5 random rows. How to do this via JPA Query (Hibernate as pro

2条回答
  •  天涯浪人
    2020-12-16 18:35

    Try calculating the random beforehand and construct your JPQL/HQL/native query with the pre-calculated random value.

提交回复
热议问题