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

标签 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;
}

最佳答案

由于更新时无法在 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);

关于java - 在 hibernate org.hibernate.hql.internal.ast.QuerySyntaxException 中更新表时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45272855/

相关文章:

php问题,怎么了?

java - Hibernate 与 Grails

hibernate - JPA 脏检查

java - Android LinearLayout 无法正确更新

java - BCrypt:使用 Spring Security 清空编码密码

mysql - rake 中止!无法加载此类文件 -- El Capitan 上的 mysql2/mysql2

php - 用于 MySQL 和 PHP 的最佳排序规则是什么?

java - Hibernate适合的继承策略

java - 在 DispatcherServlet 中未找到名称为 'dispatcher' 的 URI [/ecommerce.mv​​c/] 的 HTTP 请求的映射

java - 从另一个类调用 JFrame 的方法