Say I have the following 3 classes
@Entity
@Table(name = "tableA")
@PersistenceUnit
public class TableA{
@Id
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@GeneratedValue(generator = "UUID")
private UUID id;
@NotNull
private String sub;
@OneToMany(mappedBy = "tableA", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<TableAB> ab = new HashSet<>();
...
}
===================
@Entity
@Table(name = "tableB")
@PersistenceUnit
public class TableB {
@Id
@NotNull
@Column(name = "id", columnDefinition = "character varying(64) COLLATE pg_catalog.\"default\"")
private String id;
...
}
======================
@Entity(name="tableAb")
@PersistenceUnit
public class TableAB {
@EmbeddedId
public AbPK id;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("aId")
private TableA tableA;
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("bId")
private TableB tableB;
...
}
================================
@Embeddable
public class AbPK {
@Column(insertable = false, updatable = false)
private String bId;
@Column(insertable = false, updatable = false)
private UUID aId;
...
}
Now I want to translate my below native query into Hibernate Panache way. Is this possible in Panache? Could you please show some example of it? Or if it is not possible what is the alternative way in Panache?
select
a.id as roleId,
a.sub as roleName
from tableA as a
inner join tableAb as ab on ab.aId = a.id
inner join tableB as b on b.id = ab.bId
where b.id = '123456abcv';
If not possible with Hibernate Panache, what about with plain Hibernate?