Consider an @Entity
over a class having an id and a type which has a list which comes using a join operation on another entity.
@Entity
class A {
@Id
@Column
Long id;
@Column
String typeA;
@OneToMany
@JoinColumn(name = "ref_id")
// here a where condition
List<B> listB;
}
@Entity
class B {
@Id
@Column
Long id;
@Column
String typeB;
@Column
Long ref_id;
}
the SQL version to populate the listB is -
SELECT * FROM B JOIN A ON B.id = A.ID WHERE B.typeB = CONCAT(A.typeA,'_A_')
so A (id : 1, typeA: xx) will be linked to b[(id:2, typeB: xx_A_),(id:3,typeB: xx_A_)] and A (id : 1, typeA: yy) will be linked to b[(id:2, typeB: yy_A_),(id:3,typeB: yy_A_)]
I couldn't find a way to take property value from A or pass param to @Where annotation.