jlv
jlv copied to clipboard
Hibernate logs support
Reported by @romani, Nov 2, 2010
Add functionality to support:
- Hibernate logs detection
- View Hibernate sql as formatted text + inline arguments for convenient copy/pase to SQL Developer or other application.
- collapse few lines of Hibenate logs (SQL + Binded arguments to one row)
Reported by @romani, Mar 2, 2011
It will be useful to have separate view in Eclipse, but provided by your plugin, to convert user small chunk of hibernate log to pretty view of SQL+binding and returning table.
View layout is following:
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | SQL + params user log | -+-+-+-+-+-+-+-+-+-+-+-+-+-+ | table with returned results -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Example of user log: [11:39:30:429][SQL][DEBUG]: select this_.id as id99_0_, this_.item_id as item2_99_0_, this_.uri as uri99_0_, this_.title as title99_0_, this_.location as location99_0_ from TMS.references this_ where this_.item_id in ( ? ) [11:39:30:429][StringType][DEBUG]: binding '900000' to parameter: 1 [11:39:30:430][StringType][DEBUG]: returning '900001' as column: id99_0_ [11:39:30:431][StringType][DEBUG]: returning '900000' as column: item2_99_0_ [11:39:30:431][StringType][DEBUG]: returning 'entity:com.revere.det.core.domain.Company:8333' as column: uri99_0_ [11:39:30:431][StringType][DEBUG]: returning 'Company: The Procter & Gamble Company (PG)' as column: title99_0_ [11:39:30:431][StringType][DEBUG]: returning 'com.revere.det.core.domain.Company' as column: location99_0_ [11:39:30:431][StringType][DEBUG]: returning '900002' as column: id99_0_ [11:39:30:431][StringType][DEBUG]: returning '900000' as column: item2_99_0_ [11:39:30:431][StringType][DEBUG]: returning 'entity:com.revere.det.core.domain.Company:5758' as column: uri99_0_ [11:39:30:431][StringType][DEBUG]: returning 'Company: Johnson & Johnson (JNJ)' as column: title99_0_ [11:39:30:431][StringType][DEBUG]: returning 'com.revere.det.core.domain.Company' as column: location99_0_
moradan228
Please make sure that this view will work correctly with two cases:
- Only a subset of binding parameters is present in logs (e.g. custom user defined hibernate types can be not present in logs, or vise versa only them may be present and so forth - as different log-levels may be set for every class any combination is possible)
- Type is binded to multiple columns. This is done implementing CompositeUserType interface. It seems that if logging is done at all for these types they are done with a single string for one binding. The situation may be explored with this link: http://www.google.com/codesearch?hl=en&sa=N&q=%22implements+CompositeUserType%22+lang:java
In our projects they are logged with the single string like this: [SimplePeriodType][DEBUG]: returning '11/19/2007' as column: [start29_51_0_, start30_51_0_]
and this: [SimplePeriodType][DEBUG]: binding '11/19/2007' to parameter: [28, 29]
It seems rather reasonable, but may be not the only possible solution for logging them.
moradan228
There is one more issue with displaying returned parameters: Consider the following string:
[12:41:18:385][YesNoType][DEBUG]: returning 'false' as column: applied20406_0_
The log says that it returned 'false' for the YesNoType of boolean field. But in fact in DB this field is stored as 'Y' or 'N', so in this case DB returns us 'N' - not 'false'.
With binded parameters situation is the same:
[12:41:18:704][YesNoType][DEBUG]: binding 'true' to parameter: 4
Here in the query string 'Y' was in fact binded to the parameter 4. But it was logged as 'true'. So in general what is logged as binded and what was really binded - are different entities.
Maybe some hack for two such standard Hibernate types YesNoType and TrueFalseType (This uses chars 'T' and 'F' as codes) will be convenient? So user will be able to directly use reported SQL string at least in some more cases...
P.S. I have checked this situation only for one version of Hibernate, actually.