简体   繁体   English

RuntimeException:org.hibernate.exception.SQLGrammarException:无法执行查询

[英]RuntimeException: org.hibernate.exception.SQLGrammarException: could not execute query

i am retrieving records from a table called PurchaseDetailContributor by using another table joins.but i am getting query error. 我正在通过使用另一个表joins从名为PurchaseDetailContributor的表中检索记录,但是我收到查询错误。

below is my DAOHibernate.java class inside i worte a method. 下面是我在里面编写方法的DAOHibernate.java类。

@SuppressWarnings("unchecked")
public List<PurchaseDetailContributor> getPurchaseDetailContributorByCustomerNo(Integer customer_no) {
    System.out.println("The Customer number in PurchaseDetailContributorDAOHIbernate >>>>" + customer_no);
    String sql = " SELECT * FROM purchase_detail_contributor pdc "
             + " INNER JOIN purchasedetail pd ON pdc.purchase_detail_id = pd.purchasedetailid "
             + " INNER JOIN purchase p ON pd.purchasefk = p.purchaseid " 
             + " INNER JOIN user u ON u.userid = p.userid AND u.customer_no = " +customer_no;

    List<PurchaseDetailContributor> pdcList = new ArrayList<PurchaseDetailContributor>();
    Transaction tx = null;
    Session session = getHibernateTemplate().getSessionFactory().openSession();
    try{
        tx = session.beginTransaction();
        SQLQuery sqlQuery = session.createSQLQuery(sql).addEntity(PurchaseDetailContributor.class);
        //sqlQuery.setInteger("customer_no", customer_no);
        pdcList = sqlQuery.list();
        tx.commit();
    }catch (RuntimeException e) {
        System.out.println("getPurchaseDetailContributorByCustomerNo() >>>>- RuntimeException: " + e);
        if (tx != null && tx.isActive()) {
            try {
                // Second try catch as the rollback could fail as well
                tx.rollback();
            } catch (HibernateException e1) {
                System.out.println("Error rolling back transaction: " + e1);
            }
        }
    } finally {
        session.disconnect();
    }

my error is in join query. 我的错误是在联接查询。

//error information //错误信息

1:13:00,713 DEBUG [UserDAOHibernate:774] findUsersByCustomer_no() - Namequery: GetUsersByCustomer_no, 57835
11:13:00,752 DEBUG [UserDAOHibernate:774] findUsersByCustomer_no() - Namequery: GetUsersByCustomer_no, 57835
This COMPANYID is before passing from  FORM >>>>>>>>41
This COMPANYtype after passing id from FORM >>>>>>>>UnTrusted
The customer number is >>>>>>57835
User select values is Untrusted
Inside try condition
The Customer number in PurchaseDetailContributorDAOHIbernate *********57835
11:13:01,073 WARN  [JDBCExceptionReporter:233] SQL Error: 0, SQLState: S0022
11:13:01,074 ERROR [JDBCExceptionReporter:234] Column 'is_approved' not found.
getPurchaseDetailContributorByCustomerNo() ====222>>>>- RuntimeException: org.hibernate.exception.SQLGrammarException: could not execute query
java.lang.NullPointerException
at com.newscom.action.AccountAdminAction.updateTheCustomer(AccountAdminAction.java:4749)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:453)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:292)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:255)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)

You have no spaces in your sql 您的SQL中没有空格

String sql = "select * from purchase_detail_contributor"
         + "inner join purchasedetail on (purchase_detail_contributor.purchase_detail_id = purchasedetail.purchasedetailid)"
         + "inner join purchase on (purchasedetail.purchasefk = purchase.purchaseid)" 
         + "inner join user on (user.userid = purchase.userid)"
         + "where user.customer_no = :customer_no";

So the sql is 所以sql是

select * from purchase_detail_contributorinner join purchasedetail...

Which is definitely syntax error 这绝对是语法错误

Did you post correct code? 您输入正确的代码了吗?

As in error it shows 如错误所示

11:13:01,074 ERROR [JDBCExceptionReporter:234] Column 'is_approved' not found.

暂无
暂无

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

相关问题 嵌套的异常是org.hibernate.exception.SQLGrammarException:无法执行查询 - nested exception is org.hibernate.exception.SQLGrammarException: could not execute query 如何解决 org.hibernate.exception.SQLGrammarException: 无法执行查询 - How to solve org.hibernate.exception.SQLGrammarException: could not execute query org.hibernate.exception.SQLGrammarException:无法执行查询 - org.hibernate.exception.SQLGrammarException: could not execute query org.hibernate.exception.SQLGrammarException:无法再次执行查询 - org.hibernate.exception.SQLGrammarException: could not execute query again org.hibernate.exception.SQLGrammarException:无法执行语句 - org.hibernate.exception.SQLGrammarException: could not execute statement org.hibernate.exception.SQLGrammarException:无法执行JDBC批更新 - org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update org.hibernate.exception.SQLGrammarException:无法执行 JDBC 批量更新 - org.hibernate.exception.SQLGrammarException:Could not execute JDBC batch update org.hibernate.exception.SQLGrammarException:无法执行语句 - org.hibernate.exception.SQLGrammarException: could not execute statement 异常:org.hibernate.exception.SQLGrammarException:无法执行查询 SELECT MAX(cast(value,integer)) - Exception: org.hibernate.exception.SQLGrammarException: could not execute query SELECT MAX(cast(value,integer)) 嵌套的异常是org.hibernate.exception.SQLGrammarException:无法执行查询-添加了“ 0_” - nested exception is org.hibernate.exception.SQLGrammarException: could not execute query - “0_” added
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM