由以下原因引起:java.sql.SQLSyntaxErrorException:[SQL0205] 列 MITMAS_MMCONO 不在 table 模式中的 OOLINE 中

Caused by: java.sql.SQLSyntaxErrorException: [SQL0205] Column MITMAS_MMCONO not in table OOLINE in schema

我有 3 个实体 类

在线:

@Entity
@IdClass(OolineId.class)
@NamedQuery(name="Ooline.findAll", query="SELECT o FROM Ooline o")
public class Ooline implements Serializable 
{
    private static final long serialVersionUID = 1L;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(name="mitmas_mmcono" , referencedColumnName="mmcono"),
        @JoinColumn(name="mitmas_mmitno" , referencedColumnName="mmitno")
    })
    private Mitmas mitmas ;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(name="mitfac_m9cono", referencedColumnName="m9cono"),
        @JoinColumn(name="mitfac_m9itno", referencedColumnName="m9itno"),
        @JoinColumn(name="mitfac_m9faci", referencedColumnName="m9faci")
    })
    private Mitfac mitfac ;

    @Id
    private String obitno;
    @Id
    private BigDecimal obcono;
    @Id
    private String obfaci;

    private BigDecimal obabno;

    //getter and setters

}

米特法克:

@Entity
@IdClass(MitfacId.class)
@NamedQuery(name="Mitfac.findAll", query="SELECT m FROM Mitfac m")
public class Mitfac implements Serializable 
{
    private static final long serialVersionUID = 1L;

    @OneToMany(mappedBy="mitfac",fetch=FetchType.LAZY)
    private List<Ooline> oolineItem; 

    @Id
    private String m9itno;
    @Id
    private String m9faci;
    @Id
    private BigDecimal m9cono;

    private String m9acrf;

    private BigDecimal m9appr;

    //getter and setter

}

圣诞老人:

@Entity
@IdClass(MitmasId.class)
@NamedQuery(name="Mitmas.findAll", query="SELECT m FROM Mitmas m")
public class Mitmas implements Serializable 
{
    private static final long serialVersionUID = 1L;

    @OneToMany(mappedBy="mitmas",fetch=FetchType.LAZY)
    private List<Ooline> ooline; 

    @Id
    private String mmitno;
    @Id
    private BigDecimal mmcono;

    private BigDecimal mmaad0;

    private BigDecimal mmaad1;

    private String mmaccg;

    //getter and setter methods
}

下面是我的存储库文件:

public interface OolineRepository extends JpaRepository<Ooline, String> 
{
    public static final String ORDER_LINE_QUERY = 
            "select x.obcono,x.oborno,x.obponr, x.obposx, x.obfaci, x.obitno, x.obitds, x.oborqt, "
            + "x.oborqa, x.obwhlo, x.obadid, x.obpopn, x.obrout, x.obmodl, x.oborst,"
            + " x.obnepr, x.obdwdz, x.obcodz, x.obpldt, x.obplhm,"
            + " x.obprrf, x.obspun, x.obrgdt, x.obrgtm, x.obwhsl from Ooline x "
            + "left join x.mitmas y  left join x.mitfac z "
            + "where x.obcono = :cono and x.oborno = :orno";

    @Query(ORDER_LINE_QUERY)
    public List<Ooline> getOolineLines(@Param("cono") BigDecimal cono, @Param("orno") String orno);
}

我应该在 SQL

中执行以下查询
"select x.oborno,x.obponr, x.obposx, x.obfaci, x.obitno, x.obitds, x.oborqt, x.oborqa,
x.obwhlo, x.obadid, x.obpopn, x.obrout, x.obmodl,x.oborst, x.obnepr, x.obdwdz, x.obcodz,
x.obpldt, x.obplhm,x.obprrf, x.obspun, x.obrgdt, x.obrgtm, x.obwhsl from Ooline x join
schema.mitmas on mmcono = obcono and mmitno = obitno left join  schema.mitfac on
m9cono = obcono and m9faci = obfaci and m9itno = obitno where obcono =1 and oborno = 'asasa'";

任何人都可以验证是否已正确构造和映射实体。 但是查询并没有按照我期望的方式构建。出现错误 "Column MITMAS_MMCONO not in table OOLINE ." 谁能帮我解决这个问题

映射的实体构造正确,但未预先定义查询。您想要从子实体 Ooline 到主实体 Mitmas 的左连接,并且它试图通过将 Ooline 的主键字段连接到 Mitmas 的主键字段(参见生成的 sql)来做到这一点,这是不正确的。为什么你想要一个左连接,因为你实际上并没有使用主实体的任何东西?

我修改如下

@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(updatable=false,insertable=false,name="obcono",referencedColumnName="mmcono"),
        @JoinColumn(updatable=false,insertable=false,name="obitno",referencedColumnName="mmitno")
    })
    private Mitmas mitmas ;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(updatable=false,insertable=false,name="obcono",referencedColumnName="m9cono"),
        @JoinColumn(updatable=false,insertable=false,name="obitno",referencedColumnName="m9itno"),
        @JoinColumn(updatable=false,insertable=false,name="obfaci",referencedColumnName="m9faci")
    })
    private Mitfac mitfac ;