Skip to content

Instantly share code, notes, and snippets.

@Senorsen
Created May 15, 2022 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Senorsen/edd0fb0306fbc022be5f636eeb9c9736 to your computer and use it in GitHub Desktop.
Save Senorsen/edd0fb0306fbc022be5f636eeb9c9736 to your computer and use it in GitHub Desktop.
hql-pageable-example.kt
interface EmployeeDao : JpaRepository<Employee, Long> {
// ...
// 如果对应 Entity 字段有 eager fetch
fun findByCompanyId(companyId: Long, pageable: Pageable): Page<Employee>
// 如果对应 Entity 字段无 eager fetch
@Query("""FROM Employee e
JOIN FETCH e.department d
JOIN FETCH d.parent pd
WHERE e.companyId = :companyId
""")
fun findByCompanyId(companyId: Long, pageable: Pageable): Page<Employee>
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment