NHibernate 3 和 MySQL 中多重查询的语法错误
我曾经能够使用 MySQL 在 NHibernate 2.1 中将以下代码作为多重查询运行
var total = new LeagueInfoQuery { Count = true, User = CurrentUser }.CreateCriteria(session).FutureValue<int>();
var leagues = new LeagueInfoQuery { User = CurrentUser, PageSize = pageSize, Page = page, SortBy = sortBy, SortAsc = sortAsc }.CreateCriteria(session).Future<LeagueInfo>();
var results = PaginationHelper.CreateCustomPage<LeagueInfo>(leagues, pageSize, page, total.Value);
,其中例如 LeagueInfoQuery 只是一个可以创建标准 ICriteria 的自定义查询对象。
但是,自从升级到 NHibernate 3.0 后,我现在遇到语法错误。异常信息如下。
{“执行多条件时出错: [SELECT count(*) as y0_ FROM
League
this_ WHERE this_.User = ?p0;\r\n选择 this_.Id 作为 y0_, this_.Name 为 y1_, min(f1_.Date) 为 y2_, max(f1_.日期) 作为 y3_, 计数(不同的 t2_.Id)为 y4_ FROM联盟
this_ 内联团队
t2_ on this_.Id=t2_.League 内连接赛程
f1_ on this_.Id=f1_.League WHERE this_.User = ?p1 GROUP BY this_.Name ORDER BY y0_ desc 限制 ?p1;\r\n]"}
内部异常:
{“您的 SQL 中有错误 句法;检查手册 对应你的MySQL服务器 正确使用语法的版本 靠近 ''b68d9d4e-a958-4fb8-8490-9e4401572f38'' 在第 1 行”}
所以它看起来像一个语法错误,但这在 v2.1 中不会发生,如果我编辑消息中的 SQL,以便参数是我可以让它工作的值。
那么为什么会这样NHibernate 3.0 中现在出现错误吗?我是否需要特别针对 MySQL 语法进行配置,如果需要的话怎么办
?
I used to be able to run the following code as a multi query in NHibernate 2.1 using MySQL
var total = new LeagueInfoQuery { Count = true, User = CurrentUser }.CreateCriteria(session).FutureValue<int>();
var leagues = new LeagueInfoQuery { User = CurrentUser, PageSize = pageSize, Page = page, SortBy = sortBy, SortAsc = sortAsc }.CreateCriteria(session).Future<LeagueInfo>();
var results = PaginationHelper.CreateCustomPage<LeagueInfo>(leagues, pageSize, page, total.Value);
where e.g. LeagueInfoQuery is just a custom query object that can create a standard ICriteria.
However, since upgrading to NHibernate 3.0 I now get a syntax error. The exception message is as follows.
{"Error executing multi criteria :
[SELECT count(*) as y0_ FROMLeague
this_ WHERE this_.User =
?p0;\r\nSELECT this_.Id as y0_,
this_.Name as y1_, min(f1_.Date) as
y2_, max(f1_.Date) as y3_,
count(distinct t2_.Id) as y4_ FROMLeague
this_ inner joinTeam
t2_
on this_.Id=t2_.League inner joinFixture
f1_ on this_.Id=f1_.League
WHERE this_.User = ?p1 GROUP BY
this_.Name ORDER BY y0_ desc limit
?p1;\r\n]"}
Inner Exception:
{"You have an error in your SQL
syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near
''b68d9d4e-a958-4fb8-8490-9e4401572f38''
at line 1"}
So it looks like a syntax error but this didn't use to happen in v2.1 and if I edit the SQL in the message so that the parameters are values I can get it to work.
So why is this error now occurring in NHibernate 3.0? Do I need to configure something in particular for MySQL syntax and if so what?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 NHibernate 3 的问题,现已解决(谢谢!)
This was an issue with NHibernate 3 which has now been resolved (thanks!)