-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to see generated SQL with the actual data
PostPosted: Fri Dec 08, 2006 4:55 pm 
Newbie

Joined: Sat Dec 02, 2006 1:09 am
Posts: 12
question & rant

OK, I know this has been asked before, I have seen it posted, but I have not found a solution after looking long and hard. I want to see the actual SQL that hibernate generates along with the data in a log file or be able to dump the actual SQL to a log file that I specify.

In only one instance I am seeing SQL problems but am having a hard time knowing or seeing the actual (or partial) SQL generated (for some SQL statements the SQL is not printed even with the sql enabled param turned on).

I know there is a param to enable sql printed to the log file, but it does not include the data an only prints the ?, ?, ? what I want is the data replaced by the ?, ?, ? and be able to log this.

---
Furthermore it would be helpful if I could selectively log the statements for which an exception is thrown (sqlexception or other hibernate related exception involving the execution of the sql statement).

---
Someone suggested a way to log data by writing a toString() method on every hibernate object and logging this or putting try {} catch{} throughout my application but this is the wrong way to go about it.

If Hibernate does not have the most basic facility for me to debug my application (using the framework) by seeing what it is actually doing, we will be looking elsewhere and possibly implementing our own ORM framework.

Every interface or wrapper that I have written around JDBC supports the facility to see what it is actually doing in case there are errors and to log detailed information that will help find those errors.

In order to find the problem (any problem), you have to understand what the problem is and to understand the problem in this case it is to see what is going on (what data is being passed in each field).

I don't want (and should not have to) rewrite my entire application to do something the framework should provide, namely see exactly what it is doing when there are errors.

If there is a SQL Exception or problem of any kind, there should be a facility for:
1. Logging the problem (the actual SQL that caused the problem - actual SQL is defined as the actual statement, with the data, that is being sent to the DB)
2. Sending notification (email, pager) if needed
3. Provide a development setting that exits the app server and blows smoke out of the back of the machine when a designated problem occurs.


I know there will be people who disagree with #3 but in the software development world, it is called fail fast (and hard) which during development is what I want to do so that the annoyance factor is so high that every developer on my team sees the problem and it gets fixed as soon as possible. I am also implementing this is any other config file can not be read or parsed properly during startup.

---
I would appreciate any help, or at least a discussion in this area. There is a considerable amount of time being spent on debugging problems with Hibernate. I have seen this on more than one project and am weighing the time saving costs that are touted by the framework.

---
I grant that using Hibernate may save development time if the framework is used as intended, and everyone knows what they are doing, but I have seen some horrible things on projects that I come into where the self proclaimed architects have strangled themselves with Hibernate (and other frameworks in use on the project).

A framework used badly can lead to longer development times. I recently worked on a project using Hibernate and EJB together that should have taken only six months to complete, yet it was two years into development, hardly finished (and it was a real terd). They are still trying to polish it.

If I can figure out this SQL thing with Hibernate my faith may be restored and the Universe will be closer to order again.


r


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 5:11 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
you are welcome to submit a patch!!

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 5:31 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
If you turn on debug logging for the org.hibernate.type package, you can see the parameter bindings.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 5:33 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
As a side benefit, you will also see the object hydration from the resultset.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.