繁体   English   中英

如何使用 select 仅使用 Quarkus Panache 的某些字段?

[英]How to select only certain fields with Quarkus Panache?

Quarkus使用Panache简化了 Hibernate ORM 的映射。

这是我的entityPanacheRepository的示例:

@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();
   }

}

所有指南都解释了如何编写不同的查询,但不清楚如何 select 只有某些属性。

如果我不需要整个Person lastName ,而是我数据库中所有人的姓氏?

是否有可能 select 仅使用Quarkus Panache的某些属性?

目前这是不可能的,您可以订阅这个关于 Hibernate 投影的问题: https://github.com/quarkusio/quarkus/issues/6261

不要犹豫投票(+1 反应)并提供反馈。

正如@aksappy所说,添加了此功能,其文档可在此处获得。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM