I have been Trying to generate JPA2 Specification that can filter data by joining another table. The tables are
ApplicationUser{
String userId;
}
ExternalUser{
String userId;
}
Comment{
String message;
String userType; //appuser or externaluser
String userId; // Either the user id in ApplicationUser table or ExternalUser table
}
Now I would like to run a query to find all Comments posted by ExternalUser with this query
select comment.* from Comment inner outer join ExternalUser on (ExternalUser.userId = Comment.userId and Comment.userType = 'externaluser')
How to query this using Jpa2 Specification wihout the User table actually having a OneToMany Mapping. The user class is already fixed so cannot change it to add the relationship.
public default Specification<Comment> search(String userType,String userId) {
Specification<Comment> spec = (root, cq, cb) -> {
return predicate???
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…