I have a JpaRepository which has many elements that match the same myCriteria
. I want to change the boolean value of the latest element matching myCriteria
. This is my entity:
@Entity
@Table(name = "my_entity")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class MyEntity {
private boolean myField;
private String myCriteria;
private LocalDateTime createdAt;
}
And this is my repository and query:
public interface MyRepository extends JpaRepository<MyEntity, UUID> {
@Modifying
@Query("update MyEntity myEntity set myEntity.myField = true where myEntity.myCriteria = :myCriteria order by myEntity.createdAt limit 1")
void setAddressed(@Param("myCriteria") String myCriteria);
}
It appears that I am not using order by
properly as I am getting the following error: expecting EOF, found 'order' near line 1
. My question is how to construct this query properly?
Thank you for your time