@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
}
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)));
}
}
}
select foo
from task_management taskmanage0_
cross join tagging tagging1_
where tagging1_.task_mangement_id = taskmanage0_.id