Ondra Žižka
Ondra Žižka

Reputation: 46806

Can Hibernate generate uppercase SQL?

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

Upvotes: 0

Views: 1686

Answers (3)

Ondra Žižka
Ondra Žižka

Reputation: 46806

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.

Upvotes: 1

Pascal Thivent
Pascal Thivent

Reputation: 570385

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.

Upvotes: 3

Andy
Andy

Reputation: 14194

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>

Upvotes: 2

Related Questions