You have a table in a database based on the following class (the table's name and fields are the same):
Java
@Entity
public class Car {
@Id
@GeneratedValue
private long id;
private String model;
private int year;
// constructor, getters, setters
}
Kotlin
@Entity
class Car (
@Id
@GeneratedValue
var id: Long = 0,
var model: String = "",
var year: Int = 0
)
You want to fetch all the car objects sorted by the year from the database, from the oldest to the newest ones. Which method do you define in the repository?