gpt4 book ai didi

具有外连接的 Hibernate HQL 查询

转载 作者:行者123 更新时间:2023-12-05 05:27:58 26 4
gpt4 key购买 nike

请问如何将 OUTER 从 Informix 查询更改为 HQL 查询。当前面临错误 unexpected token:outer

SQL查询:

select a.SC_OB_PROFILE_CODE, b.SC_ORIG_SF_GROUP_CODE, f.SC_ORIG_SAC, 
f.SC_ORIG_FAC,b.SC_PROD_CONT_GROUP_CODE, d.SC_PROD_CONT_CODE, e.GP_CD, a.SC_ORIG_COUNTRY,
a.SC_DEST_COUNTRY, a.SC_DEST_SAC, a.SC_DEST_FAC, a.SC_SEND_DOW,
a.SC_OB_SORT_CODE, a.ORIG_OB_SORT_CODE, a.TARGET_OB_SORT_CODE, a.SC_TIMESTAMP
from SC_OB_TEMP_AUDIT2 a, SC_OB_ALLOCATION b, outer SC_FAC_GROUP f,
outer (SC_OB_PROD_GROUP d, GBL_PRODUCT e)
where a.SC_ORIG_COUNTRY = 'MY'
and a.EXPORT_FLAG = 'N'
and a.SC_OB_PROFILE_CODE = b.SC_OB_PROFILE_CODE
and a.SC_ORIG_COUNTRY = b.SC_ORIG_COUNTRY
and f.SC_ORIG_COUNTRY = b.SC_ORIG_COUNTRY
and b.SC_ORIG_SF_GROUP_CODE = f.SC_FAC_GROUP_CODE
and d.SC_ORIG_COUNTRY = b.SC_ORIG_COUNTRY
and b.SC_PROD_CONT_GROUP_CODE = d.SC_PROD_GROUP_CODE
and e.GP_CNT_CD = d.SC_PROD_CONT_CODE
order by a.SC_TIMESTAMP, a.SC_OB_PROFILE_CODE, a.SC_DEST_COUNTRY

HQL查询:

@SuppressWarnings("unchecked")
public List<LoginCountryEBean> getExportDetails(String country){
List<LoginCountryEBean> expDel = null;
Query q= em1.createQuery("select a.obProfileCode, b.sfGroupCode, f.orgSac," +
"f.sc_orig_fac,b.contGroupCode, d.prodContCode, e.gpCd, a.origCountry," +
"a.destCountry, a.destSac, a.destFac, a.sendDow, a.obSortCode, " +
"a.origObSortCode, a.targetObSortCode, a.timeStamp from AuditBean a, " +
"AllocationEBean b, **outer** FacGroupEBean f,**outer**(ProdGroupEBean d, glbProductEBean e)" +
"where a.origCountry :country and a.exportFlag = 'N' " +
"and a.obProfileCode = b.profileCode" +
"and a.origCountry = b.orgCountry" +
"and f.orgCountry = b.orgCountry" +
"and b.sfGroupCode = f.facGroupCode" +
"and d.orgCountry = b.orgCountry" +
"and b.contGroupCode = d.prodGroupCode" +
"and e.gpCntCd = d.prodContCode" +
"order by a.timeStamp, a.obProfileCode, a.destCountry");
q.setParameter("country", country);
expDel = q.getResultList();
return expDel;

//
AllocationEBean
package com.dhl.gls.persistence.bean;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="SC_OB_ALLOCATION")
public class AllocationEBean implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(name="sc_orig_country")
private String orgCountry;

@Id
@Column(name="sc_orig_sf_group_code")
private String sfGroupCode;

@Id
@Column(name="sc_prod_cont_group_code")
private String contGroupCode;

@Id
@Column(name="sc_ob_profile_code")
private String profileCode;

public String getOrgCountry() {
return orgCountry;
}

public void setOrgCountry(String orgCountry) {
this.orgCountry = orgCountry;
}

public String getSfGroupCode() {
return sfGroupCode;
}

public void setSfGroupCode(String sfGroupCode) {
this.sfGroupCode = sfGroupCode;
}

public String getContGroupCode() {
return contGroupCode;
}

public void setContGroupCode(String contGroupCode) {
this.contGroupCode = contGroupCode;
}

public String getProfileCode() {
return profileCode;
}

public void setProfileCode(String profileCode) {
this.profileCode = profileCode;
}


}

//
AuditEBean
package com.dhl.gls.persistence.bean;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="sc_ob_temp_audit2")
public class AuditBean implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(name="audit_Id")
private long auditId;

@Column(name="sc_ob_profile_code")
private String obProfileCode = null;


@Column(name="sc_orig_country")
private String origCountry = null;


@Column(name="sc_dest_country")
private String destCountry = null;


@Column(name="sc_dest_sac")
private String destSac = null;


@Column(name="sc_dest_fac")
private String destFac = null;


@Column(name="sc_send_dow")
private String sendDow = null;


@Column(name="sc_ob_sort_code")
private String obSortCode = null;

@Column(name="orig_ob_sort_code")
private String origObSortCode = null;

@Column(name="target_ob_sort_code")
private String targetObSortCode = null;

@Column(name="usr_id")
private String userId = null;

@Column(name="sc_timestamp")
private Date timeStamp = null;

@Column(name="export_flag")
private String exportFlag = null;

public String getObProfileCode() {
return obProfileCode;
}

public String getOrigCountry() {
return origCountry;
}

public String getDestCountry() {
return destCountry;
}

public String getDestSac() {
return destSac;
}

public String getDestFac() {
return destFac;
}

public String getSendDow() {
return sendDow;
}

public String getObSortCode() {
return obSortCode;
}

public String getOrigObSortCode() {
return origObSortCode;
}

public String getTargetObSortCode() {
return targetObSortCode;
}

public Date getTimeStamp() {
return timeStamp;
}

public String getExportFlag() {
return exportFlag;
}

public void setObProfileCode(String obProfileCode) {
this.obProfileCode = obProfileCode;
}

public void setOrigCountry(String origCountry) {
this.origCountry = origCountry;
}

public void setDestCountry(String destCountry) {
this.destCountry = destCountry;
}

public void setDestSac(String destSac) {
this.destSac = destSac;
}

public void setDestFac(String destFac) {
this.destFac = destFac;
}

public void setSendDow(String sendDow) {
this.sendDow = sendDow;
}

public void setObSortCode(String obSortCode) {
this.obSortCode = obSortCode;
}

public void setOrigObSortCode(String origObSortCode) {
this.origObSortCode = origObSortCode;
}

public void setTargetObSortCode(String targetObSortCode) {
this.targetObSortCode = targetObSortCode;
}

public void setTimeStamp(Date timeStamp) {
this.timeStamp = timeStamp;
}

public void setExportFlag(String exportFlag) {
this.exportFlag = exportFlag;
}

public long getAuditId() {
return auditId;
}

public void setAuditId(long auditId) {
this.auditId = auditId;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}
}

//
prodGroupEBean
package com.dhl.gls.persistence.bean;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="SC_OB_PROD_GROUP")
public class ProdGroupEBean implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(name="sc_orig_country")
private String orgCountry;

@Id
@Column(name="sc_prod_cont_code")
private String prodContCode;

@Id
@Column(name="sc_prod_group_code")
private String prodGroupCode;

public String getOrgCountry() {
return orgCountry;
}

public void setOrgCountry(String orgCountry) {
this.orgCountry = orgCountry;
}

public String getProdContCode() {
return prodContCode;
}

public void setProdContCode(String prodContCode) {
this.prodContCode = prodContCode;
}

public String getProdGroupCode() {
return prodGroupCode;
}

public void setProdGroupCode(String prodGroupCode) {
this.prodGroupCode = prodGroupCode;
}


}

//
FacGroupEBean
package com.dhl.gls.persistence.bean;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="SC_FAC_GROUP")
public class FacGroupEBean implements Serializable{

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(name="sc_orig_country")
private String orgCountry;

@Id
@Column(name="sc_orig_sac")
private String orgSac;

@Id
@Column(name="sc_orig_fac")
private String orgFac;

@Id
@Column(name="sc_fac_group_code")
private String facGroupCode;

public String getOrgCountry() {
return orgCountry;
}

public void setOrgCountry(String orgCountry) {
this.orgCountry = orgCountry;
}

public String getOrgSac() {
return orgSac;
}

public void setOrgSac(String orgSac) {
this.orgSac = orgSac;
}

public String getOrgFac() {
return orgFac;
}

public void setOrgFac(String orgFac) {
this.orgFac = orgFac;
}

public String getFacGroupCode() {
return facGroupCode;
}

public void setFacGroupCode(String facGroupCode) {
this.facGroupCode = facGroupCode;
}
}

//
glsproductionEBean
package com.dhl.gls.persistence.bean;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="GBL_PRODUCT")
public class glbProductEBean implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;

@Id
@Column(name="gp_cd")
private String gpCd;

@Column(name="gp_cnt_cd")
private String gpCntCd;

@Column(name="gp_sort_cd")
private String gpSortCd;

@Column(name="gp_short_nm")
private String gp_short_nm;

@Column(name="hf_lk")
private Long hfkl;

@Column(name="pasdt_cd")
private String pasdtCd;

@Column(name="psd_cd")
private Short psdCd;

@Column(name="gp_geo_markt")
private String gpGeoMarkt;

@Column(name="gp_doc_ndoc_ind")
private String gpDocNdocInd;

public String getGpCd() {
return gpCd;
}

public void setGpCd(String gpCd) {
this.gpCd = gpCd;
}

public String getGpCntCd() {
return gpCntCd;
}

public void setGpCntCd(String gpCntCd) {
this.gpCntCd = gpCntCd;
}

public String getGpSortCd() {
return gpSortCd;
}

public void setGpSortCd(String gpSortCd) {
this.gpSortCd = gpSortCd;
}

public String getGp_short_nm() {
return gp_short_nm;
}

public void setGp_short_nm(String gp_short_nm) {
this.gp_short_nm = gp_short_nm;
}

public Long getHfkl() {
return hfkl;
}

public void setHfkl(Long hfkl) {
this.hfkl = hfkl;
}

public String getPasdtCd() {
return pasdtCd;
}

public void setPasdtCd(String pasdtCd) {
this.pasdtCd = pasdtCd;
}

public Short getPsdCd() {
return psdCd;
}

public void setPsdCd(Short psdCd) {
this.psdCd = psdCd;
}

public String getGpGeoMarkt() {
return gpGeoMarkt;
}

public void setGpGeoMarkt(String gpGeoMarkt) {
this.gpGeoMarkt = gpGeoMarkt;
}

public String getGpDocNdocInd() {
return gpDocNdocInd;
}

public void setGpDocNdocInd(String gpDocNdocInd) {
this.gpDocNdocInd = gpDocNdocInd;
}

}

最佳答案

连接的语法是

select ... from Entity1 e1
[inner | left [outer]] join e1.entity2s e2
[inner | left [outer]] join e2.entity3s e3
...

阅读the documentation

关于具有外连接的 Hibernate HQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14685489/

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