RuntimeException: org.hibernate.exception.SQLGrammarException: не удалось выполнить запрос

Я извлекаю записи из таблицы с именем PurchaseDetailContributor, используя другую таблицу joins.but, я получаю ошибку запроса.

ниже мой класс DAOHibernate.java внутри метода i worte.

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

моя ошибка в запросе соединения.

// информация об ошибках

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)

java,mysql,sql,hibernate,

0

Ответов: 2


1

У вас нет пробелов в вашем 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";

Таким образом, sql

select * from purchase_detail_contributorinner join purchasedetail...

Который определенно синтаксическая ошибка


1

Вы отправили правильный код?

Как по ошибке это показывает

11:13:01,074 ERROR [JDBCExceptionReporter:234] Column 'is_approved' not found.
Java, MySQL, SQL, спящий режим,
Похожие вопросы
Яндекс.Метрика