Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Converting/Intercepting HQL to SQL

 
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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE 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
 
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
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic