Quarkus
упрощает сопоставления ORM Hibernate с помощью Panache
.
Вот пример моих entity
и PanacheRepository
:
@Entity
public class Person {
@Id @GeneratedValue private Long id;
private String firstName;
private String lastName;
private LocalDate birth;
private Status status;
}
@ApplicationScoped
public class PersonRepository implements PanacheRepository<Person> {
// example
public Person findByName(String name){
return find("name", name).firstResult();
}
// ! and this is what I tried, but it's not possible to do it this way
// all the methods return Person or something of type Person like List<Person>
// so basically this won't even compile
public List<String> findAllLastNames() {
return this.find("select p.lastName from Person p").list();
}
}
Все руководства объясняют, как писать разные запросы, но не ясно, как выбрать только определенные атрибуты.
Если мне не нужен весь объект Person
, а скорее lastName
всех людей в моей БД?
Можно ли выбрать только определенные атрибуты с помощью Quarkus Panache
?