Hibernate 可以生成大写 SQL 吗?

发布于 2024-09-06 04:33:00 字数 416 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

从﹋此江山别 2024-09-13 04:33:00

我不知道有什么方法可以直接将关键字大写。但是您可以编写自己的拦截器并实现 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.

冷清清 2024-09-13 04:33:00

我不知道这会强制使用大写,但它确实有助于提高可读性。在 hibernate.cfg.xml 中,将以下内容放入 元素中:

<!--hibernate.cfg.xml -->
<property name="format_sql">true</property>

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.cfg.xml -->
<property name="format_sql">true</property>
感悟人生的甜 2024-09-13 04:33:00

发现: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文