fix(newsletter): Do not pass DISTINCT through to SQL.
This was causing an error:
ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
Change-Id: I2de3713fa1d7ca9d6f3592840a944e16cc8faa1d
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java
index b8f2d07..949d127 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/newsletter/NewsletterSender.java
@@ -27,6 +27,7 @@
import javax.transaction.Transactional;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.hibernate.Session;
+import org.hibernate.annotations.QueryHints;
@Dependent
public class NewsletterSender {
@@ -54,16 +55,18 @@
var session = em.unwrap(Session.class);
List<Post<?>> posts =
- Post.list(
- """
- SELECT DISTINCT p FROM Post p
- JOIN p.targets r
- JOIN r.tags tag
- WHERE p.newsletter IS NULL
- AND p.scope = 'top_level'
- AND tag = 'world'
- """,
- Sort.ascending("date"));
+ Post.find(
+ """
+ SELECT DISTINCT p FROM Post p
+ JOIN p.targets r
+ JOIN r.tags tag
+ WHERE p.newsletter IS NULL
+ AND p.scope = 'top_level'
+ AND tag = 'world'
+ """,
+ Sort.ascending("date"))
+ .withHint(QueryHints.PASS_DISTINCT_THROUGH, false)
+ .list();
Post.fetchTexts(posts);
if (posts.isEmpty()) {