使用 JPA 时 HQL 的异常行为(*** 向读者提供的信息多于问题 *** )
我试图在基于 JPA 的应用程序中出于某些报告目的而触发 hql 。 我尝试的以下查询在启动时不断出现问题(因为我将其作为 NamedQuery 给出,所以在启动时检查了语法)。
不正确的查询:
SELECT t FROM Table_1 tb1
INNER JOIN
Table_2 tb2
where tb1.name = 'someName';
经过大量的排列和组合(并深入研究了查询的其他部分,这是我之前怀疑的),我意识到问题出在“t” 。 正确的查询应该是而不是上面的查询...
SELECT tb1 FROM Table_1 tb1
INNER JOIN
Table_2 tb2
where tb1.name = 'someName';
请注意,HQL 期望 tb1 与表短名“tb1”相同>”
tableName 缩写和选择不匹配只会导致我面临的问题。令人惊讶的是,hibernate/JPA 并没有在堆栈中给出错误,但部署继续运行,我最终需要终止 java 进程才能退出它。
希望这对某人有帮助。
如果有人也能解释这种行为,那就太好了。
谢谢!!
I was trying to fire hql for some reporting purpose in my JPA based application.
The following query that I tried kept conking out on startup (Since I had given it as a NamedQuery, it was checked for syntax at startup).
Incorrect Query:
SELECT t FROM Table_1 tb1
INNER JOIN
Table_2 tb2
where tb1.name = 'someName';
After lot of permutations and combinations (and digging through the other parts of the query, which I suspected earlier), I realized the problem lied in the "t". Instead of the query above, the correct query should have been...
SELECT tb1 FROM Table_1 tb1
INNER JOIN
Table_2 tb2
where tb1.name = 'someName';
Notice that HQL expects the tb1 to be same as the Table shortname "tb1"
The tableName shortform and the select mismatch only resulted in the issue that I was facing. Surprisingly, hibernate/JPA does not give an error in the stack, but the deployment keeps on running through and I need to ultimately kill the java process to get out of it.
Hope this helps someone.
It would great, if somebody could also reason this behaviour.
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处理此类语句的最佳方法是将“变量”放在 SELECT 子句中与表别名相同的实践中。
那不是
发表像
“希望”这样对未来有帮助的声明。
The best way to deal with such statements it make it a PRACTICE to put the "Variable" in the SELECT clause same as the table Alias.
That is instead of
make a statment like
Hope that helps someone in the future.
我不确定是否理解这个问题,但如果您认为 Hibernate 应该以在
EntityManagerFactory
创建时报告(或不报告)语法错误的NamedQuery
的方式进行改进,你应该创建一个问题。但我不认为它会得到高度重视。I'm not sure to understand the question but if you think that Hibernate should be improved in the way it reported (or not) your syntactically incorrect
NamedQuery
atEntityManagerFactory
creation time, you should create an issue. I don't think it will get a high priority though.