2017-07-24 34 views
0

我嘗試上載.xls文件。從那個文件我得到的值,然後更新表。在更新hibernate中的表時org.hibernate.hql.internal.ast.QuerySyntaxException

我試圖用兩個表格唯一的條件來更新表格。 同時更新這個我得到了下面的異常

"org.hibernate.hql.internal.ast.QuerySyntaxException: expecting "set", found ','" 

我將在這裏展示我的邏輯代碼。
Controller.java

HSSFSheet worksheet = workbook.getSheetAt(0); 

//         int challan= this.epzdao.getChallannoplusone(req); 
//       //Reads the data in excel file until last row is encountered 
          for(int i=0;i < worksheet.getPhysicalNumberOfRows()-1;i++) 
          { 
//        //Creates an object for the Candidate Model 

//        //Creates an object representing a single row in excel 
           HSSFRow row = worksheet.getRow(i + 1); 
           //Sets the Read data to the model class 
           String jobid = row.getCell(1).getStringCellValue(); 
           String isbn = row.getCell(7).getStringCellValue(); 
//        double challanno = row.getCell(40).getNumericCellValue(); 
           String challannoo = row.getCell(40).getStringCellValue(); 
           String taxvalue = row.getCell(48).getStringCellValue(); 
           String cgstratee = row.getCell(49).getStringCellValue(); 
           String cgstamtt = row.getCell(50).getStringCellValue(); 
           String igstratee = row.getCell(51).getStringCellValue(); 
           String igstamtt = row.getCell(52).getStringCellValue(); 
           String sgstratee = row.getCell(53).getStringCellValue(); 
           String sgstamtt = row.getCell(54).getStringCellValue(); 
           String Status = "Completed"; 

           System.out.println("============================================="); 
           System.out.println("The Jobdocketid value is:"+jobid); 
           System.out.println("The ISBN Value is:"+isbn); 
           System.out.println("The challannoo Value is:"+challannoo); 
           System.out.println("The taxvalue Value is:"+taxvalue); 
           System.out.println("The cgstratee Value is:"+cgstratee); 
           System.out.println("The cgstamtt Value is:"+cgstamtt); 
           System.out.println("The igstratee Value is:"+igstratee); 
           System.out.println("The igstamtt Value is:"+igstamtt); 
           System.out.println("The sgstratee Value is:"+sgstratee); 
           System.out.println("The sgstamtt Value is:"+sgstamtt); 
           System.out.println("The Status Value is:"+Status); 
           System.out.println("============================================="); 

           int updatedctax = this.epzdao.updatedatatax(jobid, isbn, challannoo, taxvalue, cgstratee,cgstamtt, igstratee, igstamtt, sgstratee, sgstamtt, Status); 

           if(updatedctax > 0){ 
            req.setAttribute("bodyMessageStatus", "Updated Successfully"); 
            System.out.println("Updated Successfully!"); 
           }else{ 
            req.setAttribute("bodyMessageError","Updation Failed Please try Again"); 
            System.out.println("Updated Not Successfully!"); 
           } 
        } 

ChallanDao.java

public int updatedatatax(String jobdocketid, String isbn, String challannoo, String taxvalue, String cgstratee, String cgstamtt, String igstratee, String igstamtt, String sgstratee, String sgstamtt, String status); 

ChallanDaoImpl.java

@Override 
public int updatedatatax(String jobdocketid, String isbn, String challannoo, String taxvalue, String cgstratee, String cgstamtt, String igstratee, String igstamtt, String sgstratee, String sgstamtt, String status) { 
    { 

    JobDocketStatus jobdocket = null; 
     int res = 0; 
    Session session = sessionFactory.openSession(); 
    session.beginTransaction();  
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
     Date date = new Date(); 
     System.out.println(dateFormat.format(date));  
     String datefrmt = dateFormat.format(date); 

    try { 

     Update Challan_dc p, Sales q set p.taxablevalue =:field1, p.cgstrate =:field2, p.cgstamt =:field3, p.sgstrate =:field4, p.sgstamt =:field5, p.igstrate =:field6, p.igstamt =:field7, p.status =:field10 where q.jobdocketid = p.jobDocketId and q.isbn =:field8 and p.challanno = :field9 and q.jobdocketid =:field11");     
      qry.setParameter("field1",taxvalue); 
      qry.setParameter("field2",cgstratee); 
      qry.setParameter("field3",cgstamtt); 
      qry.setParameter("field4",igstratee); 
      qry.setParameter("field5",igstamtt); 
      qry.setParameter("field6",sgstratee); 
      qry.setParameter("field7",sgstamtt); 
      qry.setParameter("field8",isbn); 
      qry.setParameter("field9",challannoo); 
      qry.setParameter("field10",status); 
      qry.setParameter("field11", jobdocketid); 



     res = qry.executeUpdate(); 
     System.out.println("res count" + res); 
     session.getTransaction().commit(); 
    } catch (Exception e) 
    { 
     e.printStackTrace(); 
     //return list(); 
    } 
    finally 
    { 
     session.close(); 
    } 
    return res; 
} 
+0

你是如何合併數據?使用em.merge或executeUpdate(); ?? – Ashish451

+0

executeUpdate() – Aoryouncellvan

+0

您可以更新代碼,以便我可以幫助您 – sForSujit

回答

0

正如你不能在HQL使用JOIN在更新,你可以使用Subqueries代替。

這裏http://docs.jboss.org/hibernate/orm/5.0/manual/en-US/html_single/#batch-direct

看看你可以試試這個查詢,或者修改爲您的要求。

Update Challan_dc p 
SET 
p.taxablevalue =:field1, p.cgstrate =:field2, p.cgstamt =:field3, p.sgstrate =:field4, p.sgstamt =:field5, p.igstrate =:field6, p.igstamt =:field7, p.status =:field10 
where 
q.isbn =:field8 
and p.challanno = :field9 
and p.jobDocketId IN (select q.jobdocketid from Sales q); 
//OR 
and p.jobDocketId = (select q.jobdocketid from Sales q where some conditon); 
0

我們需要根據父表和子表創建hibernate映射文件。因爲父更新也會導致子updatd。

相關問題