How to write a JPA query that make a join between 2 entities that doesn’t share any reference between them I mean no Relation has been defined in the mapping
EntityA
@Id
long id
String field1
String field2
EntityB
@Id
String field1
@Id
String field2
How can I write a join like This in JPQL
select entityB from entityA,entityB
where entityB.field1 = entityA.field1
and entityB.field2 = entityA.field2
Thanks
You’re thinking in SQL, not ORM. In ORM, you create relationships between entities (
@OneToMany,@ManyToOne,@ManyToMany, etc.), and the ORM uses those relationships to determine how it should join them together.You need to update your entities to have those relationships, and then traverse the object model to do what your want to do.
Here is a place to get started: http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-association