Hibernate Issuing select statement even if FetchMode = Join

后端 未结 4 1800
挽巷
挽巷 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:17

    I'm using the criteria query to fetch Customers.

    public class PurchaseOrder
    {
        .....
        .....      
        @ManyToOne(fetch=FetchType.EAGER, optional=true)
        @JoinColumn(name="ReportingCustomer_ID", nullable=true, insertable=false, updatable=false)
        @Fetch(FetchMode.JOIN)
        @NotFound(action=NotFoundAction.IGNORE)
        public ReportingCustomer getReportingCustomer()
        {
            return reportingCustomer;
        }
    }
    

    While getting PurchaseOrder it does a LEFT OUTER JOIN as below

    select ... from PurchaseOrder this_ left outer join ReportingCustomer reportingc2_ 
    on this_.ReportingCustomer_ID=reportingc2_.ReportingCustomer_ID
    where ...
    
    1. When there is an entry in ReportingCustomer - It fires only the above query.
    2. When there is no entry for that record in ReportingCustomer - It fires a query for each PURCHASEORDER (m+1) queries.

    I use "Progress" driver to connect to DB. I'm not sure why it fires m+1 queries only in scenario 2.

提交回复
热议问题