Reputation: 1
I'm struggling to order my JSON list by datetime. Here's what I did
public class Post {
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
private long id;
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date postedAt;
And this is the query as it shown below from the repo :
@Query(value = "SELECT * FROM Post u WHERE u.supervisor_id = ?1
ORDER BY convert(datetime,u.postedAt,121) ASC", nativeQuery = true)
List findPostsBySupervisorId(Long id);
but it's not working. What should I do to get my list ordered?
Upvotes: 0
Views: 169
Reputation:
I am not big fan of @Query
, there are better ways, e.g. repository methods like findAllByOrderByPostedAtAsc
, but if you have to, then what is reason not using just order by u.postedAt
?
Upvotes: 1