Announcement Announcement Module
No announcement yet.
left join with JpaSpecificationExecutor Specification ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • left join with JpaSpecificationExecutor Specification ?

    Hi ,

    Im using the JpaSpecificationExecutor, I have an entity with a lazily fetched collection.

    public class CategoryItemEvent implements Serializable {

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id

    CategoryItem categoryItem

    During my spring data query which uses Specifications predicates, it seems to make an extra sql call for every row in the result set (n+1 problem i guess), so I was wondering if I could somehow do a left join in my Speciifcation to avoid these extra calls ? finding CriteriaBuilder a bit complicated. (cant use querydsl as it cannot process my Groovy entities because of APT or something)

    public static Specification<CategoryItemEvent> isHotel() {
    return new Specification<CategoryItemEvent>() {
    Predicate toPredicate(Root<CategoryItemEvent> categoryItemEventRoot, CriteriaQuery<?> query,
    CriteriaBuilder builder) {

    return builder.equal(categoryItemEventRoot.<CategoryItem> get("categoryItem").<com.funnelscope.ql.entity.Cat egory> get("category").<Long> get("id"),