Hibernate 本机查询错误
当尝试在休眠中执行本机查询时,我收到一个奇怪的错误,这是我的查询:
String qsf = "LEFT OUTER JOIN record_v2_record_audit rra ON r.record_id = rra.record_id "
+ "LEFT OUTER JOIN record_audit ra ON rra.record_audit_id = ra.record_audit_id AND rra.record_audit_id = ra.record_audit_id "
+ "LEFT OUTER JOIN repeating_field rf ON r.record_id = rf.record_id "
+ "LEFT OUTER JOIN repeating_field_field rff ON rf.repeating_field_id = rff.repeating_field_id "
+ "LEFT OUTER JOIN field_v2 f ON rff.field_id = f.field_id AND rff.field_id = f.field_id "
+ "LEFT OUTER JOIN field_image_v2 fi ON f.field_id = fi.field_id "
+ "WHERE r.record_type_id = 1 "
+ "AND r.public_access = 0 "
+ "AND r.status = 'A' "
+ "AND ra.process_type = 'A' "
+ "AND rf.field_type_id = 100032011 "
+ "AND fi.public_access = 'A'";
qsc = "SELECT COUNT(DISTINCT r.record_id) FROM record_v2 r "
+ qsf + " ;";
并且我这样执行查询:
BigInteger totalRecords = (BigInteger) entityManager.createNativeQuery(
qsc).getSingleResult();
但我收到此错误:
javax.persistence.PersistenceException:org.hibernate.exception.SQLGrammarException:无法执行查询
,真正让我困惑的是:
引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行“limit 2”附近使用的正确语法
在堆栈跟踪中出现的第 1 行“limit 2”附近使用的正确语法。
MySQl 管理查询执行时没有错误,所以我在这里不知所措。
我在 Ubuntu 10.10 中使用 JBoss 5 和 JDBC 5.1.15。
预先感谢您的任何帮助...!
I am getting a strange error when trying to execute a native query in hibernate this is my query:
String qsf = "LEFT OUTER JOIN record_v2_record_audit rra ON r.record_id = rra.record_id "
+ "LEFT OUTER JOIN record_audit ra ON rra.record_audit_id = ra.record_audit_id AND rra.record_audit_id = ra.record_audit_id "
+ "LEFT OUTER JOIN repeating_field rf ON r.record_id = rf.record_id "
+ "LEFT OUTER JOIN repeating_field_field rff ON rf.repeating_field_id = rff.repeating_field_id "
+ "LEFT OUTER JOIN field_v2 f ON rff.field_id = f.field_id AND rff.field_id = f.field_id "
+ "LEFT OUTER JOIN field_image_v2 fi ON f.field_id = fi.field_id "
+ "WHERE r.record_type_id = 1 "
+ "AND r.public_access = 0 "
+ "AND r.status = 'A' "
+ "AND ra.process_type = 'A' "
+ "AND rf.field_type_id = 100032011 "
+ "AND fi.public_access = 'A'";
qsc = "SELECT COUNT(DISTINCT r.record_id) FROM record_v2 r "
+ qsf + " ;";
And I execute the query thuswise:
BigInteger totalRecords = (BigInteger) entityManager.createNativeQuery(
qsc).getSingleResult();
But I am getting this error:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
and the bit that is really throwing me is this:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'limit 2' at line 1
appearing in the stacktrace.
The query executes without error from MySQl admin so I am at a loss here.
I am using JBoss 5 with JDBC 5.1.15 in Ubuntu 10.10.
Thanks in advance for any help...!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜问题是由尾随分号引起的,尝试将其删除:
I guess the problem is caused by the trailing semicolon, try to remove it: