加载中...
加载中...
hibernate left join fetch

hibernate left join fetch 原创

写一个hql,其中用到了 left join fetch ,最后报错:   

2021-02-23 09:23:24,911 ERROR [qtp383124839-17] dispatcher.DefaultDispatcherErrorHandler (CommonsLogger.java:42) - Exception occurred during processing request: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=cb_ba_BANK_ACCOUNT,tableAlias=cbbankacco1_,origin=cb_ba_withdraw withdraw0_,colums={withdraw0_.accountId_ ,className=com.skysz.app.cb.bank.domain.CbBankAccount}}] [select w.id, w.status, w.message, w.submitTime, w.createBy.name as user, w.businessNO, w.account.accountNO from com.skysz.app.cb.withdraw.domain.WithDraw w left join fetch w.account left join w.createBy where 1=1 and to_char(w.submitTime,'yyyy-mm-dd') = ?]
org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=cb_ba_BANK_ACCOUNT,tableAlias=cbbankacco1_,origin=cb_ba_withdraw withdraw0_,colums={withdraw0_.accountId_ ,className=com.skysz.app.cb.bank.domain.CbBankAccount}}] [select w.id, w.status, w.message, w.submitTime, w.createBy.name as user, w.businessNO, w.account.accountNO from com.skysz.app.cb.withdraw.domain.WithDraw w left join fetch w.account left join w.createBy where 1=1 and to_char(w.submitTime,'yyyy-mm-dd') = ?]

原语句

select w.id, w.status, w.message, w.submitTime, w.createBy.name as user, w.businessNO, w.account.accountNO from WithDraw w left join fetch w.account left join w.createBy where 1=1

原因:select后面不是对象,用了w.status去部分字段,所以不能用 left join fetch

下面语句正常。

from WithDraw w left join fetch w.account left join fetch w.createBy where 1=1


总结:

1、select后面不是对象,用了w.status 去部分字段就不能用 left join fetch

2、取对象,不取部分字段,可以使用left join fetch




没有更多推荐了 [去首页]
image
文章
357
原创
284
转载
73
翻译
0
访问量
199063
喜欢
47
粉丝
6
码龄
5年
资源
0

文章目录

加载中...
0
0