JPA 2 Criteria Fetch Path Navigation

前端 未结 6 661
我寻月下人不归
我寻月下人不归 2020-12-08 14:38

With JPA 2 Criteria Join method I can do the following:

    //Join Example (default inner join)
    int age = 25;
    CriteriaBuilder cb = entityManager.getC         


        
6条回答
  •  自闭症患者
    2020-12-08 15:03

    Agree with you about that method, and the fact that you would expect it to allow what you say. Another option would be

    Join p = t.join(Team_.players);
    t.fetch(Team_.players);
    c.select(t).where(cb.equal(p.get(Player_.age), age));
    

    i.e do a join(), add a fetch() for it, and then make use of the join. This is illogical and only adds to the inelegant nature of JPA Criteria, but anyway, ought to be a workaround

提交回复
热议问题