I need to join two entities using hibernate annotations. I tried few ways, but i didnt found a solution.
The point of my problem is that: tables should be joined when first key (String) contains second key (Long), like this: first = {ABC:12345678XYZ}, second = 12345678
in sql it could be like this:
SELECT *
FROM entityB
LEFT JOIN entityA
ON '{"ABC":'||entityB.id||'XYZ}' = entityA.stringWithEntityBId
Here is an classes example and one of my latest try:
public class EntityA {
private Long id;
private String stringWithEntityBId;
}
public class EntityB {
private Long id;
@OneToMany
@JoinTable(
name="EntityA",
joinColumns = @JoinColumn( name="id"),
inverseJoinColumns = @JoinColumn( name="stringWithEntityBId"))
@WhereJoinTable(clause=" entityA.stringWithEntityBId = '{\"ABC\":'||entityB.id||'XYZ}' ")
private List<EntityA> entityiesA;
}
Could anyone give me an example how to solve that? Thanks!