In this time this is possible in following manner:
I'm using Spring data JPA 2.1.10.
I have two entities:
@Entity
@Getter
@Setter
public class TaskManagement {
private Long id;
private String title;
//Some other attributes
}
@Entity
@Getter
@Setter
public class Tagging {
private Long id;
private String name;
private String taskManagementId;
//Some other attributes
}
Tasks can have Some tags. but there isn't any relation between TaskManagement and Tag entities.
To search taskmanagements i used TaskManagementSpecification like this:
public class TaskManagementSpecification implements Specification<TaskManagement> {
private final TaskManagementSearchDto taskManagementSearchDto;
@Override
public Predicate toPredicate(Root<TaskManagement> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> andClause = new ArrayList<>();
//To Cross join TaskManagement to Tagging that they are unrelated
if (!CollectionUtils.isEmpty(taskManagementSearchDto.getTagIds())) {
Root<Tagging> taggingRoot = criteriaQuery.from(Tagging.class);
andClause.add(criteriaBuilder.equal(taggingRoot.get("taskManagementId"), root.get(TaskManagement_.ID)));
}
}
}
The result query is:
select foo
from task_management taskmanage0_
cross join tagging tagging1_
where tagging1_.task_mangement_id = taskmanage0_.id