Quarkus
使用 . 简化 Hibernate ORM 映射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
?