KB Article #178985
Enable SQL debug with parameter values
Problem
-- Per default, logging of SQL queries will not show values of SQL parameters
-- Instead it will only show questionmarks (?), e.g.: an error attempting to enter too big data into one column:
Caused by: <openjpa-0.0.0-rnull fatal general error> org.apache.openjpa.persistence.PersistenceException: Data truncation {prepstmnt 845137154 UPDATE Messages SET ConsumptionFilename = ?, ConsumptionUrl = ?, ContentMimeType = ?, CurrentStateType = ?, Direction = ?, DocumentClass = ?, ProductionFilename = ?, ReceiverRoutingID = ?, ReceiverRoutingIDType = ?, ResubmitInfo = ?, SenderRoutingID = ?, SenderRoutingIDType = ?, JdoVersion = ?, ConsumptionExchangePointOID = ?, CurrentStateOID = ? WHERE OID = ? AND JdoVersion = ? [params=?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?]} [code=0, state=22001]
-- It is not clear which of the above parameters is actually too big for which field
-- Same is true for all SQL logging, e.g. when enabling "log4j.category.openjpa.jdbc.SQL=debug"
Resolution
In order to enable SQL debug and see the parameters of the SQL queries follow these steps:- Create a backup-copy of the [installDir]/Interchange/conf/datastoreconfig.xml
- Change the
<Property key="openjpa.Log" value="slf4j"/>
to
<Property key="openjpa.Log" value="log4j"/> - Below the "<Property key="openjpa.Log" value="log4j"/>" line in the <Properties> section add this line:
<Property key="openjpa.ConnectionFactoryProperties" value="PrintParameters=true,PrettyPrint=true,PrettyPrintLineLength=72"/> - "PrettyPrint=true,PrettyPrintLineLength=72" are optional, see comment below
- Edit [installDir]/Interchange/conf/log4j.xml:
Change:
<Logger name="openjpa.jdbc.SQL" level="WARN" />
to:
<Logger name="openjpa.jdbc.SQL" level="DEBUG" /> - Restart B2Bi
- Reproduce issue
- Check logs.
Additional info:
** The datastoreconfig <Properties> should look like this:
<Properties> <Property key="openjpa.DataCache" value="true"/> <Property key="openjpa.ConnectionRetainMode" value="on-demand"/> <Property key="openjpa.ConnectionDriverName" value="com.cyclonecommerce.jdbc.AxwayBoneCPDataSource"/> <Property key="openjpa.Log" value="log4j"/> <Property key="openjpa.ConnectionFactoryProperties" value="PrintParameters=true,PrettyPrint=true,PrettyPrintLineLength=72"/> </Properties>
** "PrintParameters=true" will cause the parameter values to show up.
** "PrettyPrint=true" will show the SQL queries with '_' characters to indicate linebreaks, which can via text editor replaced by linebreaks to increase readability to the logfile itself. ** The replacement of linebreaks with '_' characters is a setting in the log4j.xml under the <Appenders> section
** Default value for "PrettyPrintLineLength" is 60 columns,
** Instead of adding the above to the datastoreconfig.xml, one can add the following to the jvmArguments.xml instead, allowing this to become effective only on the required node (cn or te):
<Property key="openjpa.ConnectionFactoryProperties">PrintParameters=true,PrettyPrint=true,PrettyPrintLineLength=72</Property>