gpt4 book ai didi

java - 像在 Hibernate 中一样选择

转载 作者:行者123 更新时间:2023-12-02 07:37:13 25 4
gpt4 key购买 nike

我想在 HQL 中编写以下 SQL 查询 -

select * from ITPMAST 
inner join STKMAST on ITPMAST.ITPITP=STKMAST.stkstk where STKMAST.STKSIT='S101'

Itpmast 类

public class Itpmast implements java.io.Serializable {

private String itpitp;
private Sizmast sizmast;
private User usdmastByItpaddusd;
private User usdmastByItpamdusd;
private Prmmast prmmast;
private Sctmast sctmast;
private String itpnam;
private short itpfcn;
private short itptcn;
private BigDecimal itpcpr;
private BigDecimal itpspr;
private String itpactyn;
private String itpbscode;
private String itpcolor;
private BigDecimal itpspr1;
private BigDecimal itpspr2;
private BigDecimal itpspr3;
private Date itpsactddt1;
private Date itpsactddt2;
private Date itpsactddt3;
private Date itpaddddt;
private String itpaddtime;
private Date itpamdddt;
private String itpamdtime;
private Short itpbscodeord;
private String itptrnactno;
private String itpactcode;
private Date itpsactddt;
private String itpprtflg;
private Set<Skumast> skumasts = new HashSet<Skumast>(0);
private Set<Igpmast> igpmasts = new HashSet<Igpmast>(0);
private Set<Dismastb> dismastbs = new HashSet<Dismastb>(0);
private Set<Dismastd> dismastds = new HashSet<Dismastd>(0);
private Set<Rbttran> rbttrans = new HashSet<Rbttran>(0);
private Set<Lytmast> lytmasts = new HashSet<Lytmast>(0);
private Set<Stkmast> stkmasts = new HashSet<Stkmast>(0);
private Set<Sslmast> sslmastsForSslitp = new HashSet<Sslmast>(0);
private Set<Sslmast> sslmastsForSslssl = new HashSet<Sslmast>(0);
}

Stkmast级

public class Stkmast implements java.io.Serializable {

private StkmastId id;
private User usdmastByStkamdusd;
private User usdmastByStkaddusd;
private Sctmast sctmast;
private Sitmast sitmast;
private Itpmast itpmast;
private BigDecimal stksohqty;
private BigDecimal stksohqty01;
private BigDecimal stksohqty02;
private BigDecimal stksohqty03;
private BigDecimal stksohqty04;
private BigDecimal stksohqty05;
private BigDecimal stksohqty06;
private BigDecimal stksohqty07;
private BigDecimal stksohqty08;
private BigDecimal stksohqty09;
private BigDecimal stksohqty10;
private BigDecimal stksohqty11;
private BigDecimal stksohqty12;
private BigDecimal stksohqty13;
private BigDecimal stksohqty14;
private BigDecimal stksohqty15;
private BigDecimal stksohqty16;
private BigDecimal stksohqty17;
private BigDecimal stksohqty18;
private BigDecimal stksohqty19;
private BigDecimal stksohqty20;
private Date stkaddddt;
private String stkaddtime;
private Date stkamdddt;
private String stkamdtime;
private String stkcat;
private Date stkltddt;
private Date stklsalddt;
private Date stklpurddt;
private Date stklsalrtddt;
private Date stklpurrtddt;
private Date stklshortddt;
private Date stklexcessddt;
private Date stkltransferin;
private Date stkltransferout;
private BigDecimal stkmedsohqty;
private BigDecimal stkmedsohqty01;
private BigDecimal stkmedsohqty02;
private BigDecimal stkmedsohqty03;
private BigDecimal stkmedsohqty04;
private BigDecimal stkmedsohqty05;
private BigDecimal stkmedsohqty06;
private BigDecimal stkmedsohqty07;
private BigDecimal stkmedsohqty08;
private BigDecimal stkmedsohqty09;
private BigDecimal stkmedsohqty10;
private BigDecimal stkmedsohqty11;
private BigDecimal stkmedsohqty12;
private BigDecimal stkmedsohqty13;
private BigDecimal stkmedsohqty14;
private BigDecimal stkmedsohqty15;
private BigDecimal stkmedsohqty16;
private BigDecimal stkmedsohqty17;
private BigDecimal stkmedsohqty18;
private BigDecimal stkmedsohqty19;
private BigDecimal stkmedsohqty20;
}

我最好的尝试是

from Stkmast s 
join fetch s.itpmast i where s.sitmast.sitsit=:siteCode and i.itpitp like :code

但是这个HQL查询会产生许多SQL查询来获取数据。谢谢。

最佳答案

您需要将映射中的获取类型设置为 join,而不是默认的 select

Example :

<hibernate-mapping>
<class name="com.mkyong.common.Stock" table="stock">
<set name="stockDailyRecords" cascade="all" inverse="true"
table="stock_daily_record" batch-size="10" fetch="join">
<key>
<column name="STOCK_ID" not-null="true" />
</key>
<one-to-many class="com.mkyong.common.StockDailyRecord" />
</set>
</class>
</hibernate-mapping>

关于java - 像在 Hibernate 中一样选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12050404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com