我使用 Hibernate 和非常简单的 Criteria API,但具有复杂的数据链接。有时在加载实体后,我会在日志中看到以下 SQL:
select * from ( select this_.ID as ID7_0_, from AAA.CUSTOMER this_ where this_.STATUS=? and this_.ID in (select this_.ID_CUSTOMER as y0_ from AAA.CUSTOMER_CONTACT this_ where this_.ID_CONTACT in (select this_.ID as y0_ from AAA.CONTACT this_ where this_.PHONE_NUMBER=?) and this_.ROLE=?) ) where rownum <= ?
但我不明白为什么 Hibernate 决定生成子选择而不通过外键链接(它们都指向 hbm.xml)。为什么有子选择?我只使用 fetch="select" 或 fetch="join"。
有任何想法吗?