简体   繁体   中英

How do I use row_number (or anything with same behavior) with Hibernate Criteria API?

I want to implement a similar query with CriteriaBuilder API:

SELECT *, ROW_NUMBER() OVER( ORDER BY Student_Score) AS RowNumberRank
FROM StudentScore

The main problem is that JPQL doesn't support window functions and I don't know how to replicate their behavior...

Analytical functions are vendor specific. This makes is hard to implement with a CriteriaBuilder API. Using native query ties your java application to a specific database vendor. To avoid that you can create a vendor specific view and create in your java application a select with the criteria api using that view.

Beside the StudentScore entity you already have you had to define a (readonly) StudentScoreView entity with the extra attribute rowNumberRand which you can use in your JPQL query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM