I need to join two JPA entities on a property when there is no FK/PK relation between the two.
I am using Hibernate and can use HQL query like this
select foo, bar from FooEntity as foo, BarEntity as bar
where foo.someothercol = 'foo' and foo.somecol = bar.somecol
However, I want to avoid dependency on Hibernate and use EntityManager instead.
Please help.
Your query is valid JPQL and does not use Hibernate specific functionality (just space between bar and from is missing). In JPA 2.0 specification (4.4.5 Joins) this is explained with following words:
Main difference to your query is that your select contains two types of entities. Result of query is List of Object[]. Order of elements in array is same as in select
statement. Following works in your case: