Sorting the data

Report a typo

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 Product {
    
    @Id
    @GeneratedValue
    private long id;
    private String model;
    private String type;
    private int price;

    // constructor, getters, setters
}
Kotlin
@Entity
data class Product(
    @Id
    @GeneratedValue
    var id: Long = 0,
    var model: String = "",
    var type: String = "",
    var price: Int = 0
)

How do you get the instance of Sort that will help you fetch the data from the database sorted by price: from cheaper to more expensive? Choose all possible options.

Java
  1. Sort productSort = Sort.by("price");
  2. Sort productSort = Sort.by("price").ascending();
  3. Sort productSort = Sort.by(Sort.Direction.ASC, "price");
  4. Sort productSort = Sort.by("price", Sort.Direction.ASC);
Kotlin
  1. val productSort: Sort = Sort.by("price")
  2. val productSort: Sort = Sort.by(Sort.Order.asc("price"))
  3. val productSort: Sort = Sort.by(Sort.Direction.ASC, "price")
  4. val productSort: Sort = Sort.by(Sort.Order.asc("price"))
Select one or more options from the list
___

Create a free account to access the full topic