views:

45

answers:

3

Somewhere way inside JBoss in a hibernate query I'm catching an error that leaves me with a ResultSet. This code is a plugged in custom data type.

It would be nice if I could simple do rs.getStatement().toString() and be done with it, but that unfortunately doesn't give away anything about the sql statement that went into it.

I was thinking doing something with ((PreparedStatement)rs.getStatement()).getMetaData().

I really wished hibernate would be a little more informative when it runs into errors. Does anyone have a good solution to help reveal which table and which column that was used when the exception occurred?

+1  A: 

One way you can debug Hibernate is by turning on its detailed logging.

For example, you can log all SQL statements as they are executed by turning on logging for org.hibernate.SQL. From here you should be able to narrow down the last statement executed prior to your exception.

Documentation can be found here.

Ben Hoffstein
Will the log indicate which one caused an error?
Mike
A: 

getting the MetaData for the ResultSet will not allow you to get the info that was passed in. In Hibernate you can have the statements be output to a log file.

Most JDBC drivers allow you to set tracing so that you can debug.

Romain Hippeau
If the log file shows a stream of sql statements, how do you find the matching one that caused the error?
Mike
@Mike - Your best bet then is to look into JDBC Driver tracing. Most drivers will support this and if there are any errors getting sent back to the client they will tell you. (The client can be an application server). What Database are you using, or specifically what driver are you using (Not the Application Server wrapper, even though in some cases they might support giving you some more details) ?
Romain Hippeau
@Romain - There are no JDBC errors. The error is in the custom data type converter that's invoked by hibernate.
Mike
@Mike - Maybe, instead of asking how to get a solution that is impossible to work, you actually gave us details on your problem we might be able to help.
Romain Hippeau
+2  A: 

Simply enable SQL logging in the Hibernate configuration properties by setting the hibernate.show_sql property to true.

This more reliable than examining the result sets metadata since the where clause is not available.

stacker
If the log file shows a stream of sql statements, how do you find the matching one that caused the error?
Mike