I have a JPA repository for a DB entity as follows:
@Repository
public interface StudentRepository
extends JpaRepository<Student, String> {
}
Student entity is as follows:
@Entity
@Table(name = "student")
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "custom-uuid")
@GenericGenerator(name = "custom-uuid",
strategy = "generator.CustomUUIDGenerator")
private String id;
@Column(name = "roll_number")
private String rollNumber;
@Column(name = "name")
private String name;
@LastModifiedDate
@Column(name = "last_modified_date")
@JsonIgnore
private Instant lastModifiedDate = Instant.now();
Now, I would like to write the following SQL query using JPA as follows:
SELECT id, roll_number from student where id=<id> order by last_modified_date desc;
Being new to JPA/Hibernate, I don't have an idea how to achieve this using JPA/Hibernate.
Could anyone please help here ?