Hibernate 可以生成大写 SQL 吗?
Hibernate可以生成大写SQL吗? 即某些选项会使其发送
SELECT table1_.prop1_ FROM my_table AS table1_;
而不是当前的
select table1_.prop1_ from my_table as table1_;
,我认为可读性要差得多,尤其是。对于长查询,HBN 往往会吐槽。 另请参阅https://forum.hibernate.org/viewtopic.php? f=1&t=932412
谢谢
can Hibernate generate uppercase SQL?
I.e. some option which would make it send
SELECT table1_.prop1_ FROM my_table AS table1_;
instead of current
select table1_.prop1_ from my_table as table1_;
which I consider far less readable, esp. for long queries HBN tends to spit.
See also https://forum.hibernate.org/viewtopic.php?f=1&t=932412
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道有什么方法可以直接将关键字大写。但是您可以编写自己的拦截器并实现
ohInterceptor#onPrepareStatement(String)
根据需要转换 sql 字符串。I'm not aware of a way to upper case the keywords only out-of-the-box. But you could write your own interceptor and implement
o.h.Interceptor#onPrepareStatement(String)
to transform the sql string as you like.我不知道这会强制使用大写,但它确实有助于提高可读性。在 hibernate.cfg.xml 中,将以下内容放入
元素中:I don't know that this will enforce uppercase, but it does help with readability. In your hibernate.cfg.xml place the following in your
<session-factory>
element:发现:Hibernate 团队之王严格反对这样的选项:
http:// opensource.atlassian.com/projects/hibernate/browse/HB-1070
对于任何寻找此内容的人,请在那里发表评论(您不能对已解决的问题进行投票:( )
更新: 另一种解决方案是替换 hibernate 的 .jar 中的 FreeMarker 模板。Found: The King of the Hibernate team is strictly against such option:
http://opensource.atlassian.com/projects/hibernate/browse/HB-1070
For anyone looking for this, please comment there (you can't vote on closed issues :( )
Update: Another solution is to replace the FreeMarker templates in hibernate's .jar's.