GET /wiki/{pageName}: Optimize HQL query.
Change-Id: I2e1852aa230fed5dc106629fb9b0aa0d85a8a0cf
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
index 8f25254..ebed4e2 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/wiki/WikiResource.java
@@ -44,7 +44,12 @@
@Produces(TEXT_HTML)
public TemplateInstance getPage(@PathParam("pageName") String pageName) {
Optional<WikiPageRevision> maybePage =
- WikiPageRevision.find("title = ?1", Sort.by("date").descending(), pageName)
+ WikiPageRevision.find(
+ "from WikiPageRevision rev"
+ + " join fetch rev.author"
+ + " where rev.title = ?1",
+ Sort.by("date").descending(),
+ pageName)
.firstResultOptional();
if (maybePage.isEmpty()) {
throw new NotFoundException();