Search code examples
quarkusquarkus-panache

Fetch specific columns from an entity but not the entire entity


I have an entity:

@Entity
public class MailingList extends PanacheEntity{
public String name;
public String email;
public Organization organization;
.
.
.
}

So, I am trying to write a query to simply return me a list having the id and email only but not a list of the MailingList entities. I am using MySQL and I want something as shown here. I have read through different documentation but I haven't found something to solve my problem. Please help out.


Solution

  • Yes,

    With panache it is possible to use DTO projections like in hibernate or jpa.

    Here you have an example from the quarkus panache documentation on how to achieve a projection of only certain fields.