Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting/Intercepting HQL to SQL

 
Lisa Ray
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using Hibernate ORM 3. I have two queries:
1. Is there a tool which shows the exact native SQL that Hibernate Generates. If we turn on show-sql, it displays SQL but with placeholders like ?.

2. By default saveOrUpdate() or update() tries to update every possible column in the DB even though just a single column changed. This is not the best performance strategy. Is there a workaround?

Thanks
Lisa
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. Is there a tool which shows the exact native SQL that Hibernate Generates. If we turn on show-sql, it displays SQL but with placeholders like ?.

You can turn on debug logging for org.hibernate.type and you'll see the bound values. Alternatively p6spy will expose bound parameters in PreparedStatements.


2. By default saveOrUpdate() or update() tries to update every possible column in the DB even though just a single column changed. This is not the best performance strategy. Is there a workaround?

No. This is just one of the trade offs of using an ORM. Is this much of a performance concern though? Unless your table uses very large data types or has a lot of indices I doubt it iwould be that bad. If you have a performance issue you could always swap to using HQL (or SQL) to do the update for the problematic table.
 
Lisa Ray
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for the reply. I think I've got answers to my questions.

Just to add, I think I can use dynamic-update attribute in Hibernate mapping file to avoid updating every possible column.


Thanks
Lisa
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I knew it but I got late. We also have dynamic-insert for insertion. They both are class level attribute.
 
Lisa Ray
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
I found a very useful DB logging tool which is bundled with WLS. Read the BEA doc.

http://download.oracle.com/docs/cd/E12840_01/wls/docs103/jdbc_drivers/spy.html


However, the log output produces for Hibernate queries is the same as the output produced by Hibernate logger. It shows all placeholders with ? not the actual vales. Is there any way to configure the same??


- Lisa
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic