Hibernate Issuing select statement even if FetchMode = Join

后端 未结 4 1858
挽巷
挽巷 2021-02-01 15:41

I have a userAccount entity mapped with a country entity . The country mapping in UserAccount class is like this

@ManyToOne(fetch=FetchType.EAGER)
@Fetch(FetchMo         


        
4条回答
  •  误落风尘
    2021-02-01 16:13

    I try use @Fetch(FetchMode.JOIN) hibernate adnotation in all api (JPQL and CriteriaBuilder) but didn't work. Only this code in service class work fine:

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery cq = cb.createQuery(UserAccount.class);
    Root o = cq.from(UserAccount.class);
    
    o.fetch("country",JoinType.INNER);
    
    em.createQuery(cq.select(o)).getResultList();
    

提交回复
热议问题