我的代码中存在此错误:
"Request processing failed; nested exception is javax.persistence.PersistenceException:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet] con causa raíz
com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-206,
SQLSTATE=42703, SQLERRMC=INVOICESEL2_.CODE_K, DRIVER=4.14.88"
我找不到错误,我知道SQL代码-206引用的对象是在无效的上下文中指定的。
我的代码是这样的:
public InvoiceSeller getSellerByEmail(String email, String debtorCode) {
String qString = "SELECT d FROM " + InvoiceSeller.class.getSimpleName() + " d "
+ " INNER JOIN "+ InvoiceSellerContact.class.getSimpleName() + " sc "
+ " ON d.code = sc.invoiceSeller.code AND d.invoiceDebtor.code = sc.invoiceSeller.invoiceDebtor.code "
+ " INNER JOIN "+ Contact.class.getSimpleName() + " c ON sc.contact.id = c.id "
+ " INNER JOIN " + ActiveRegisterMaster.class.getSimpleName() + " a "
+ " ON d.code = a.code AND d.invoiceDebtor.code = a.invoiceDebtor "
+ " WHERE a.tableName = :tablename AND d.invoiceDebtor.code = :debtorCode "
+ " AND c.email = :email AND d.status = :status";
TypedQuery<InvoiceSeller> query = this.em.createQuery(qString, InvoiceSeller.class);
System.out.println(qString);
System.out.println(query.getFirstResult());
query.setParameter("debtorCode", debtorCode);
query.setParameter("email", email);
query.setParameter("tablename", InvoiceSeller.TABLENAME);
query.setParameter("status", "A");
InvoiceSeller seller = query.getSingleResult();
System.out.println(seller.toString());
return seller;
}
谢谢!
答案 0 :(得分:0)
您的HQL是错误的,请记住,HQL语法不同于SQL,并且当您调用=VALUE("red")
时,您正在尝试创建HQL。
因此,您的HQL应该是这样的:
select * from SOME_VIEW
union all select a0,b0,c0,d0... from dual
union all select a1,b1,c1,d1... from dual
...
请注意,我在INNER JOIN之后删除了 ON 关键字,因为HQL不需要它。