简体   繁体   English

org.hibernate.exception.SQLGrammarException: 无法准备语句; 嵌套异常是 javax.persistence.PersistenceException

[英]org.hibernate.exception.SQLGrammarException: could not prepare statement; nested exception is javax.persistence.PersistenceException

I have 3 entity classes我有 3 个实体类

Ooline:油液:

@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

}

Mitfac:翻译:

@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

}

Mitmas:米特斯:

@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
}

And following is my Repository file:以下是我的存储库文件:

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);
}

And the following persistense.xml而下面的persistense.xml

<persistence-unit name="tables">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

        <class>xxx.Mitmas</class>
        <class>xxx.Ooline</class>
        <class>xxx.Mitfac</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />

            <!-- These options seem intended to be developers tools and not to facilitate 
                any production level databases -->
            <property name="hibernate.hbm2ddl.auto" value="none" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.connection.charSet" value="UTF-8" />
            <property name="hibernate.connection.driver_class" value="com.ibm.as400.access.AS400JDBCDriver" />
            <property name="hibernate.connection.url" value="jdbc:as400://host/schema" />
            <property name="hibernate.connection.username" value="username" />
            <property name="hibernate.connection.password" value="password" />

        </properties> 
    </persistence-unit>

I am supposed to execute following query in SQL我应该在 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
m3fdbdem.mitmas on mmcono = obcono and mmitno = obitno left join  m3fdbdem.mitfac on
m9cono = obcono and m9faci = obfaci and m9itno = obitno where obcono =1 and oborno = 'asasa'";

Can anyone verify if have constructed and mapped entity correctly任何人都可以验证是否已正确构造和映射实体

您应该将属性mitfac添加到xxx.Mitmas类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“main”中的异常 javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: 无法执行语句 - Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement javax.persistence.PersistenceException:org.hibernate.exception.SQLGrammarException:无法执行查询 - javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: 无法使用 heroku PostgreSQL 执行查询 - javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query with heroku PostgreSQL javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: 无法提取 ResultSet - javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet Spring boot 2.1.9 - CriteriaBuilder javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: 无法准备语句 - Spring boot 2.1.9 - CriteriaBuilder javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not prepare statement 线程“主”javax.persistence.PersistenceException 中的异常:org.hibernate.exception.ConstraintViolationException:无法执行语句 - Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement org.hibernate.exception.SQLGrammarException:无法准备语句— Spring ROO - org.hibernate.exception.SQLGrammarException: could not prepare statement — Spring ROO org.hibernate.exception.SQLGrammarException:无法准备语句 - org.hibernate.exception.SQLGrammarException: could not prepare statement java- javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:无法执行语句 - java- javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException:could not execute statement Estado HTTP 500-请求处理失败; 嵌套的异常是org.hibernate.exception.SQLGrammarException:无法准备语句 - Estado HTTP 500 - Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM