aspose file tools
The moose likes Object Relational Mapping and the fly likes Converting/Intercepting HQL to SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Converting/Intercepting HQL to SQL " Watch "Converting/Intercepting HQL to SQL " New topic
Author

Converting/Intercepting HQL to SQL

Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
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

Joined: Apr 14, 2004
Posts: 10336


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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
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

Joined: Aug 16, 2007
Posts: 1374
Yeah I knew it but I got late. We also have dynamic-insert for insertion. They both are class level attribute.
Lisa Ray
Greenhorn

Joined: Mar 05, 2009
Posts: 22
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting/Intercepting HQL to SQL
 
Similar Threads
How to persist only the value which changed?
Problem with Sybase stored proc in hibernate
Hibernate throwing SAXPasesExceptions
Hibernate: Default Binding of database field
Hibernate keeps updating database.