Eka (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZDQzZGEyNTdm...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-17054?atlOrigin=eyJpIjoiZDQzZG...
) HHH-17054 (
https://hibernate.atlassian.net/browse/HHH-17054?atlOrigin=eyJpIjoiZDQzZG...
) The existence of curly braces in the native query impact the fetch script (
https://hibernate.atlassian.net/browse/HHH-17054?atlOrigin=eyJpIjoiZDQzZG...
)
Change By: Eka (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=70121%3...
)
Hi guys, our team tries to upgrade Hibernate from 5.3.3 to 6.2.1, I have a question now.
Do the curly braces in the native query impact the eager fetch? I have a
PortfolioRuleCheck entity that has a bag setting using lazy="false" for the
PortfolioRuleCheckComment entity. Due to the lazy="false" setting, the native
query for PORTFOLIO_RULE_CHECK should also retrieve associated
PORTFOLIO_RULE_CHECK_COMMENT entries.
{code:xml}<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD
3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="abc.core.model.PortfolioRuleCheck"
table="PORTFOLIO_RULE_CHECK">
...
...
<bag name="comments" cascade="all" order-by="createDate
asc" lazy="false">
<key column="ruleCheckId" not-null="true"
foreign-key="RULE_CHECK_COMMENT_UFK"/>
<one-to-many class="abc.core.model.PortfolioRuleCheckComment"/>
</bag>
...
...
</class>
</hibernate-mapping>{code}
It works in Hibernate 5.3.3 but doesn't work in Hibernate 6.2.1.
{code:java}// Execute the native query with {}
public List<PortfolioRuleCheck> getPortfolioRuleChecksWithParentheses() {
final String sql = "select {p.*} from PORTFOLIO_RULE_CHECK p";
final NativeQuery query = getSession().createNativeQuery(sql);
query.addRoot("p", PortfolioRuleCheck.class);
return query.list();
}{code}
{code:sql}-- The script when executing getPortfolioRuleChecksWithParentheses in Hibernate
5.3.3, it tries to query PORTFOLIO_RULE_CHECK & PORTFOLIO_RULE_CHECK_COMMENT
2023-08-07 09:57:48 [61993] [main] DEBUG [SQL] select p.ID as ID1_131_0_, p.Rule as
Rule2_131_0_, p.Portfolio as Portfoli3_131_0_, p.Client as Client4_131_0_, p.Depot as
Depot5_131_0_, p.Security as Security6_131_0_, p.Currency as Currency7_131_0_,
p.FxOutright as FxOutrig8_131_0_, p.Visibility as Visibili9_131_0_, p.ValuationDate as
Valuati10_131_0_, p.MaxLossInPeriod as MaxLoss11_131_0_, p.Priority as Priorit12_131_0_,
p.Erroneous as Erroneo13_131_0_, p.Compliant as Complia14_131_0_, p.OverRuled as
OverRul15_131_0_, p.Subject as Subject16_131_0_, p.Object as Object17_131_0_, p.Predicate
as Predica18_131_0_, p.BreachDate as BreachD19_131_0_, p.acknowledged as acknowl20_131_0_,
p.notified as notifie21_131_0_, p.AcknowledgedDate as Acknowl22_131_0_, p.CreateDate as
CreateD23_131_0_, p.ModifyDate as ModifyD24_131_0_, p.Process as Process25_131_0_, p.issue
as issue26_131_0_, p.DESCRIPTION as DESCRIP27_131_0_ from PORTFOLIO_RULE_CHECK p
2023-08-07 09:57:48 [61993] [main] DEBUG [SQL] select comments0_.ruleCheckId as
ruleChec5_132_0_, comments0_.ID as ID1_132_0_, comments0_.ID as ID1_132_1_,
comments0_.author as author2_132_1_, comments0_.content as content3_132_1_,
comments0_.createDate as createDa4_132_1_ from PORTFOLIO_RULE_CHECK_COMMENT comments0_
where comments0_.ruleCheckId=? order by comments0_.createDate asc
2023-08-07 09:57:48 [61993] [main] DEBUG [SQL] select comments0_.ruleCheckId as
ruleChec5_132_0_, comments0_.ID as ID1_132_0_, comments0_.ID as ID1_132_1_,
comments0_.author as author2_132_1_, comments0_.content as content3_132_1_,
comments0_.createDate as createDa4_132_1_ from PORTFOLIO_RULE_CHECK_COMMENT comments0_
where comments0_.ruleCheckId=? order by comments0_.createDate asc{code}
{code:sql}--The script when executing getPortfolioRuleChecksWithParentheses in Hibernate
6.2.1, only fetches PORTFOLIO_RULE_CHECK
2023-08-07 10:03:24 [63363] [main] DEBUG [SQL] select p.ID id1_131_0_,p.acknowledged
acknowl20_131_0_,p.AcknowledgedDate acknowl22_131_0_,p.BreachDate
breachd19_131_0_,p.Client client4_131_0_,p.Compliant complia14_131_0_,p.CreateDate
created23_131_0_,p.Currency currency7_131_0_,p.Depot depot5_131_0_,p.DESCRIPTION
descrip27_131_0_,p.Erroneous erroneo13_131_0_,p.FxOutright fxoutrig8_131_0_,p.issue
issue26_131_0_,p.MaxLossInPeriod maxloss11_131_0_,p.ModifyDate modifyd24_131_0_,p.notified
notifie21_131_0_,p.Object object17_131_0_,p.OverRuled overrul15_131_0_,p.Portfolio
portfoli3_131_0_,p.Predicate predica18_131_0_,p.Priority priorit12_131_0_,p.Process
process25_131_0_,p.Rule rule2_131_0_,p.Security security6_131_0_,p.Subject
subject16_131_0_,p.ValuationDate valuati10_131_0_,p.Visibility visibili9_131_0_ from
PORTFOLIO_RULE_CHECK p{code}
(
https://hibernate.atlassian.net/browse/HHH-17054#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-17054#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100234- sha1:90f5128 )