ManyToOne単方向および双方向リレーションシップのJPQLクエリ
class ParentEntity{
@Id
String parentId1; //composite key
@Id
String parentId2;
@ManyToOne
ChildEntity childEntityRef;
}
class ChildEntity { //ManyToOne Unidirectional Relationship case
@Id
String childId1; //composite key
@Id
String childId2;
}
or
class ChildEntity { //ManyToOne Bidirectional Relationship case
@Id
String childId1; //composite key
@Id
String childId2;
@OneToMany
List<ParentEntity> parentEntitiesref;
}
_______________________________________________________________________
|| ParentEntity Table || ChildEntity Table ||
||_________________________________________||__________________________||
parentId1|parentId2|childId1_FK|childId1_FK|| childId1| childId2 ||
||_______|_________|___________|___________||_________|________________||
|| p11 |p21 | c11 |c21 || c11 | c21 ||
|| p12 |p22 | c11 |c21 || c12 | c22 ||
|| p13 |p23 | c12 |c22 || c13 | c23 ||
|| p14 |p24 | c12 |c22 || | ||
||_______|_________|___________|___________||_________|________________||
特定の ParentEntity に接続されていないすべての childEntity のリストにアクセスするには、JPQL クエリが必要です (単方向および双方向の関係の両方で)。
Example -
For ParentEntity[p11,p21] get All other disconnected List of ChildEntity([c12,c22],[c13,c23])
よろしく、
ガウラフ・グプタ。