首页 > 解决方案 > 在 Hibernate 中加入的预期路径

问题描述

我有 2 张桌子:

表

在我的 GnrlOrgChargeCode.java 文件中,我有:

    private Set<IOrgChargeCodeCond> orgChargeCodeConds;
    @OneToMany(mappedBy = "gnrlOrgChargeCode", targetEntity = OrgChargeCodeCond.class,
            fetch = FetchType.LAZY)
    public Set<IOrgChargeCodeCond> getOrgChargeCodeConds() {
        return orgChargeCodeConds;
    }

    public void setOrgChargeCodeConds(Set<IOrgChargeCodeCond> orgChargeCodeConds) {
        this.orgChargeCodeConds = orgChargeCodeConds;
    }

在我的 OrgChargeCodeCond 文件中:

    private IGnrlOrgChargeCode gnrlOrgChargeCode;
    @ManyToOne(targetEntity = GnrlOrgChargeCode.class,
            fetch = FetchType.LAZY)
    @JoinColumn(name = "ORG_CHARGE_CODE_ID", insertable=false, updatable=false)
    public IGnrlOrgChargeCode getGnrlOrgChargeCode() {
        return gnrlOrgChargeCode;
    }
    public void setGnrlOrgChargeCode(IGnrlOrgChargeCode gnrlOrgChargeCode) {
        this.gnrlOrgChargeCode = gnrlOrgChargeCode;
    }

我的休眠查询是:

from GnrlOrgChargeCode gocc left join OrgChargeCodeCond occc where gocc.orgId = ?

但我收到一个错误:

预计加入的路径!

请帮忙。谢谢。

标签: javaspringhibernate

解决方案


你需要一个像from GnrlOrgChargeCode gocc left fetch join gocc.orgChargeCodeConds occc where gocc.orgId = ?. 除此之外,从 5.1 版开始支持实体连接。由于您收到此错误,因此您似乎使用的是旧版本。我建议您尽快更新,因为您很可能不会收到对旧版本的任何实质性支持/帮助。


推荐阅读