NHibernate HQL批量更新失败,“指定的方法不受支持”异常

时间:2011-03-03 14:54:13

标签: nhibernate hql

尝试为Order实体执行HQL批量更新时,我遇到以下异常:

   Specified method is not supported.
   at NHibernate.Hql.Ast.ANTLR.PolymorphicQuerySourceDetector.GetClassName(IASTNode querySource)
   at NHibernate.Hql.Ast.ANTLR.PolymorphicQuerySourceDetector.Process(IASTNode tree)
   at NHibernate.Hql.Ast.ANTLR.AstPolymorphicProcessor.Process()
   at NHibernate.Hql.Ast.ANTLR.AstPolymorphicProcessor.Process(IASTNode ast, ISessionFactoryImplementor factory)
   at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
   at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
   at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters)
   at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow)
   at NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString)
   at ...Repositories.OrderRepository.MarkAsConfirmed(IEnumerable`1 orderIds) in C:\Users\Miroslav\Documents\Projects\...\OrderRepository.cs:line 40
   at ConfirmationUploadTask.Execute()

请注意,订单实体已映射到订单表,因此不应是任何与保留关键字相关的问题。其他基于LINQ 2 NHibernate的查询正常工作。当使用其他映射实体而不是Order时,查询可以正常工作。

我也试过了hbm2ddl.keywords=auto-quote as mentioned by Fabio,但没有运气。

作为参考,这是查询的样子:

var query = GetSession().CreateQuery(
    "update Order set IsConfirmed = :isConfirmed where id in (:ids)");

当使用CreateSQLQuery时,它可以正常工作:

var query = GetSession().CreateSQLQuery(
    "UPDATE Orders SET IsConfirmed = :isConfirmed WHERE OrderId in (:ids)");

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

我认为这是一个错误;请在http://jira.nhforge.org

打开一张票

作为解决方法,限定Order实体的名称。例如:

update MyProj.Domain.Order set IsConfirmed = :isConfirmed where id in (:ids)