org.hibernate.exception.SQLGrammarException: 无法准备语句;嵌套异常是 javax.persistence.PersistenceException
org.hibernate.exception.SQLGrammarException: could not prepare statement; nested exception is javax.persistence.PersistenceException
我有 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);
}
以及以下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>
我应该在 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'";
任何人都可以验证是否已正确构造和映射实体
您应该将 属性 mitfac
添加到 xxx.Mitmas
class。
我有 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);
}
以及以下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>
我应该在 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'";
任何人都可以验证是否已正确构造和映射实体
您应该将 属性 mitfac
添加到 xxx.Mitmas
class。