From eea38d578bfb29d119d6b1ba55c96b1dc570ed20 Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Wed, 19 Jan 2022 09:40:29 +0100 Subject: [PATCH] Sort events at query --- .../main/java/com/vpr/server/data/Event.java | 29 ++----------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/server/src/main/java/com/vpr/server/data/Event.java b/server/src/main/java/com/vpr/server/data/Event.java index dc11e4e..91b1e5e 100644 --- a/server/src/main/java/com/vpr/server/data/Event.java +++ b/server/src/main/java/com/vpr/server/data/Event.java @@ -5,32 +5,6 @@ import java.io.Serializable; import java.sql.Time; import java.util.List; -/* -@NamedNativeQuery(name = "findEventsInDateRange", - query = "SELECT e.id as id, e.name as name, e.priority as priority, e.is_full_day as isFullDay, " + - "is_private as isPrivate, e.start as start, e.end as end " + - "FROM event e " + - "INNER JOIN user_event ue " + - "ON e.id = ue.event_id " + - "WHERE (ue.user_id = :userId OR e.is_private = 0) " + - "AND ue.date > :startDate " + - "AND ue.date < :endDate", - resultSetMapping = "Mapping.Event" -) -@SqlResultSetMapping(name = "Mapping.Event", - classes = @ConstructorResult(targetClass = Event.class, - columns = { - @ColumnResult(name = "id"), - @ColumnResult(name = "name"), - @ColumnResult(name = "priority"), - @ColumnResult(name = "isFullDay"), - @ColumnResult(name = "isPrivate"), - @ColumnResult(name = "start"), - @ColumnResult(name = "end") - } - ) -) -*/ @Entity(name = "Event") // @Entity creates a table out of this class with Hibernate @Table(name = "event") @NamedNativeQueries({ @@ -47,7 +21,8 @@ import java.util.List; "ON e.id = ue.event_id " + "WHERE (ue.user_id = :userId OR e.is_private = 0) " + "AND ue.date > :startDate " + - "AND ue.date < :endDate", + "AND ue.date < :endDate " + + "ORDER BY ue.date, e.priority DESC, e.start", resultClass = Event.class ), @NamedNativeQuery(