Announcement Announcement Module
Collapse
No announcement yet.
left join with JpaSpecificationExecutor Specification ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    Long id

    @NotNull
    @ManyToOne
    @JoinColumn(name='itemId')
    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"), CategoryName.HOTEL.id)
    }
    }
    }
Working...
X