From 601508f7937710040a3347ece5d94efc91ffb855 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Tue, 8 Nov 2022 21:42:59 +0100 Subject: 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 --- .../benki/newsletter/NewsletterSender.java | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/main') 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.persistence.PersistenceContext; 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 @@ public class NewsletterSender { var session = em.unwrap(Session.class); List> 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()) { -- cgit v1.2.3