在hibernate中更新查询

时间:2014-06-12 15:36:50

标签: java mysql sql hibernate

我在hibernate下面有update查询我想在执行查询时更新BudgetAllocatedToFormations表的列

this.session.createQuery("UPDATE BudgetAllocatedToFormations batf,BudgetAssignedSubHeadOfAccounts bashoa,BudgetSubHeadOfAccounts bshoa "
    + " SET batf.balanceBudget = "+balanceBudget+""
    + " WHERE batf.budgetAssignedSubHeadOfAccounts.budgetAssignedSubHeadOfAccountId = bashoa.budgetAssignedSubHeadOfAccountId"
    + " AND bashoa.budgetSubHeadOfAccounts.budgetSubHeadOfAccountId = bshoa.budgetSubHeadOfAccountId"
    + " AND bshoa.budgetSubHeadOfAccountId = "+subHeadOfAccountId+""
    + " AND bashoa.budgetFormations.budgetFormationId = "+formationId+""
    + " AND batf.budgetFinancialYear.budgetFinancialYearId = "+financialYearId+""
    + " AND batf.isApproved = 1 AND batf.isLocked = 1 AND batf.isActive = 1").executeUpdate();
我明白了 错误:

ERROR [org.hibernate.hql.internal.ast.ErrorCounter] line 1:94: expecting "set", found ','
ERROR [org.hibernate.hql.internal.ast.ErrorCounter] line 1:94: expecting "set", found ',' 
line 1:94: expecting "set", found ','
    at antlr.Parser.match(Parser.java:211)
    at org.hibernate.hql.internal.antlr.HqlBaseParser.setClause(HqlBaseParser.java:414)
    at org.hibernate.hql.internal.antlr.HqlBaseParser.updateStatement(HqlBaseParser.java:216)
    at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(HqlBaseParser.java:140)

我使用的是hibernate 4.0版本。

1 个答案:

答案 0 :(得分:0)

编辑: 您的双引号未正确放置。您应该使用参数(命名或位置)而不是连接。