Nhibernate - How to debug “Antlr.Runtime.NoViableAltException”?

人盡茶涼 提交于 2019-12-05 17:42:24

Have a look at NHibernate Query Analyzer. It is not perfect, but it will be helpful in many situations.

I can't help you directly, here's something I can share.

When dealing with hibernate or nhibernate (NH), I generally debug by enabling logging on the nhibernate's log4net, or/and the logging of queries at the DB side (e.g. mysql).

They can tell me what is the queries being formulated and executed at the DB and what are the exceptions thrown back by the DB.

For instance, if you have the following error:

Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. near line 1, column
745 [select afe.AFEDataId, afe.Name, afe.AdditionalDescription, afe.ProjectType, 
afe.BusinessUnit, afe.plantId, afe.fuelTypeId, afe.DisplayStatus, afe.BudgetedAmount, 
sum(exp.Amount), afe.CreatedDate from Company.AFE.Model.AFEData as afe inner join 
afe.Expenditures as exp inner join exp.ExpenditureType  where (afe.Status.StatusId = 
:statusId) and (afe.IsRestrictedVisibility = false OR (select count(AFEDataId) from 
Company.AFE.Model.Reader as r where r.AFEData.AFEDataId = afe.AFEDataId AND 
r.Contact.ContactId = '70bc6350-c466-40d5-a067-9d1f00bed7dc') > 0 OR (select count(AFEDataId) 
from Company.AFE.Model.Editor as e where e.AFEData.AFEDataId = afe.AFEDataId AND 
e.Contact.ContactId = '70bc6350-c466-40d5-a067-9d1f00bed7dc') > 0 OR 1=1)  afe.AFEDataId, 
afe.Name, afe.AdditionalDescription, afe.ProjectType, afe.BusinessUnit, afe.plantId, 
afe.fuelTypeId, afe.DisplayStatus, afe.BudgetedAmount, afe.CreatedDate  order by afe.Name ASC]

Go and look at character 745 from the original query that was provided and check to see if there is a spelling error, as there was in this one that I just looked at.

Which version of NH you used, for the latest version, the query exchange has some updated, such as you can't use "count(1)" in query, must change to count([alias name]), NH will translate to "select class.id from ... "

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!