3

I want to get two values from two different sql tables.

In sql we would do "Select a.value, b.value from A a inner join B b on a.id = b.id where ..."

Is it possible to do it with panache? Like join two entities or something like that?

Can't really find much about joins with quarkus panache.

JohnP
  • 33
  • 4

1 Answers1

4

Panache doesn't have any specific way to deal with joins.

You can still load specific fields using HQL and projections:

List<EntitiesView> results = EntityA
    .find("Select a.value, b.value from A a inner join B b on a.id = b.id where ...")
    .project(EntitiesView.class)
    .list(); 

Where EntitiesView is:

@RegisterForReflection 
class EntitiesView {
   public final Object valueA;
   public final Object valueB;

   public EntitiesView(Object valueA, Object valueB) {
       this.valueA = valueA;
       this.valueB = valueB;
   }
}

You can find more details about projections on the Panache guide.

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30