Question

I have 2 entity classes Product and ProductAltID with no @OnetoMany mapping defined between them.

I want to do something like this

select p from ProductAltid inner join Product pai
where p.id = pai.id

How can I achieve this?

Was it helpful?

Solution

Add this method to the ProductAltId repository (choosing that one because the query returns ProductAltIds):

@Query("select pai from ProductAltId as pai " 
+ "where pai.id in (select p.id from Product as p)")
List<ProductAltId> findForAllProducts();

I switched the aliases around, they seem backward in your example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top