在hibernate org.hibernate.hql.internal.ast.QuerySyntaxException中更新表时

时间:2017-07-24 04:54:35

标签: java mysql hibernate

我尝试上传.xls文件。从该文件中我获取值,然后更新表。

尝试使用两个表唯一的条件更新表。 在更新时,我得到了以下异常

"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;
}

2 个答案:

答案 0 :(得分:0)

由于您在更新时无法在JOIN中使用HQL,因此您可以使用Subqueries代替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);

在这里查看http://docs.jboss.org/hibernate/orm/5.0/manual/en-US/html_single/#batch-direct

您可以尝试此查询,也可以根据需要进行修改。

HADOOP_CONF_DIR

答案 1 :(得分:0)

我们需要根据父表和子表创建hibernate映射文件.hbm。因为父更新也会导致子更新。