<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Andreas Höhmann&#039;s Weblog &#187; Log4J</title>
	<atom:link href="http://ahoehma.wordpress.com/category/softwareentwicklung/java/log4j/feed/" rel="self" type="application/rss+xml" />
	<link>http://ahoehma.wordpress.com</link>
	<description></description>
	<lastBuildDate>Thu, 26 Nov 2009 15:53:12 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='ahoehma.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/6b74f500a29ea048aa3d7a14adc1a24f?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Andreas Höhmann&#039;s Weblog &#187; Log4J</title>
		<link>http://ahoehma.wordpress.com</link>
	</image>
			<item>
		<title>Hibernate sql logging with values</title>
		<link>http://ahoehma.wordpress.com/2009/06/03/hibernate-sql-logging-with-values/</link>
		<comments>http://ahoehma.wordpress.com/2009/06/03/hibernate-sql-logging-with-values/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 10:02:03 +0000</pubDate>
		<dc:creator>Andreas Höhmann</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Log4J]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[jdbc]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://ahoehma.wordpress.com/?p=174</guid>
		<description><![CDATA[As you might know already, Hibernate supports logging for sql-statements. Your Spring-configuration (e.g. spring-database.xml) must contain this:


&#60;bean id=&#34;entityManagerFactory&#34;
 class=&#34;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&#34;&#62;
&#60;property name=&#34;dataSource&#34; ref=&#34;dataSource&#34; /&#62;
&#60;property name=&#34;persistenceUnitName&#34; value=&#34;logging-test&#34; /&#62;
&#60;property name=&#34;jpaVendorAdapter&#34;&#62;
 &#60;bean&#62;
&#60;property name=&#34;showSql&#34; value=&#34;true&#34; /&#62;
&#60;property name=&#34;generateDdl&#34; value=&#34;true&#34; /&#62;
&#60;property name=&#34;databasePlatform&#34; value=&#34;${jpa.hibernate.dialect}&#34; /&#62;
 &#60;/bean&#62;
 &#60;/property&#62;
&#60;property name=&#34;jpaProperties&#34; value=&#34;hibernate.dialect=${jpa.hibernate.dialect}&#34; /&#62;
 &#60;/bean&#62;

With showSql=true hibernate will show you logmessages like this:
Hibernate:
   delete
   [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ahoehma.wordpress.com&blog=1781916&post=174&subd=ahoehma&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As you might know already, Hibernate supports logging for sql-statements. Your Spring-configuration (e.g. spring-database.xml) must contain this:</p>
<pre class="brush: xml;">

&lt;bean id=&quot;entityManagerFactory&quot;
 class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot;&gt;
&lt;property name=&quot;dataSource&quot; ref=&quot;dataSource&quot; /&gt;
&lt;property name=&quot;persistenceUnitName&quot; value=&quot;logging-test&quot; /&gt;
&lt;property name=&quot;jpaVendorAdapter&quot;&gt;
 &lt;bean&gt;
&lt;property name=&quot;showSql&quot; value=&quot;true&quot; /&gt;
&lt;property name=&quot;generateDdl&quot; value=&quot;true&quot; /&gt;
&lt;property name=&quot;databasePlatform&quot; value=&quot;${jpa.hibernate.dialect}&quot; /&gt;
 &lt;/bean&gt;
 &lt;/property&gt;
&lt;property name=&quot;jpaProperties&quot; value=&quot;hibernate.dialect=${jpa.hibernate.dialect}&quot; /&gt;
 &lt;/bean&gt;
</pre>
<p>With <strong>showSql=true</strong> hibernate will show you logmessages like this:</p>
<pre>Hibernate:
   delete
   from
      SoftwareCategory_SoftwareCategory
   where
      SoftwareCategory_id=?
Hibernate:
   update
      SoftwareCategory
   set
      concurrentVersion=?,
      CATEGORY_NAME=?,
      PARENT_ID=?
   where
      id=?
      and concurrentVersion=?
Hibernate:
   insert
   into
      SoftwareCategory_SoftwareCategory
      (SoftwareCategory_id, POSITION, children_id)
   values
      (?, ?, ?)</pre>
<p>To see the values and not the placeholders (?) you must define the loglevel <strong>trace</strong> for <strong>hibernate-types</strong> in the log4j.xml:</p>
<pre class="brush: xml;">

&lt;category name=&quot;org.hibernate.type&quot;&gt;
&lt;priority value=&quot;trace&quot; /&gt;
 &lt;/category&gt;
</pre>
<p>Then you will see logmessages like this:</p>
<pre>Hibernate:
   insert
   into
      SoftwareCategory_SoftwareCategory
      (SoftwareCategory_id, POSITION, children_id)
   values
      (?, ?, ?)
NullableType:151 - binding '68' to parameter: 1
NullableType:151 - binding '0' to parameter: 2
NullableType:151 - binding '69' to parameter: 3</pre>
<p>Not bad but there is a better way for this <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Yesterday i found the project <a href="http://jdbclogger.sourceforge.net" target="_blank"><strong>JDBCLogger</strong></a>.  They have implemented a &#8220;JDBC-Proxy&#8221; with logging support. Its <a href="http://maven.apache.org/" target="_blank">Maven</a>-ready and comes with a easy <a href="http://www.springsource.org/" target="_blank">Spring</a>-integration. So how can we use this cool stuff &#8230; it is so easy:</p>
<p>1. Define the JDBCLogger dependencies in the pom.xml:</p>
<pre class="brush: xml;">

&lt;dependencies&gt;
&lt;dependency&gt;
 &lt;groupId&gt;net.sourceforge.jdbclogger&lt;/groupId&gt;
 &lt;artifactId&gt;jdbclogger-core&lt;/artifactId&gt;
 &lt;version&gt;0.7-SNAPSHOT&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;dependency&gt;
 &lt;groupId&gt;net.sourceforge.jdbclogger&lt;/groupId&gt;
 &lt;artifactId&gt;jdbclogger-spring&lt;/artifactId&gt;
 &lt;version&gt;0.7-SNAPSHOT&lt;/version&gt;
 &lt;/dependency&gt;
 &lt;/dependencies&gt;
</pre>
<p>The informations from the installation-guide on the project-site is a little too old, so the maven-repository http://jdbclogger.sourceforge.net/m2-repo/ doesn&#8217;t exists. No problem we can build jdbclogger-core and jdbclogger-spring by ourself (<a href="http://jdbclogger.sourceforge.net/building-maven.html" target="_blank">read more</a>). The simplest way to build the two artifacts is:</p>
<ul>
<li>checkout from  svn</li>
<li>edit master-pom, comment out all modules, leave only core and spring active</li>
<li>run mvn clean install from root-dir</li>
</ul>
<p>2. Change your Spring-configuration, switch showSql off and add the following bean:</p>
<pre class="brush: xml;">

&lt;bean id=&quot;jdbcLoggerConfig&quot;
 class=&quot;net.sourceforge.jdbclogger.spring.JdbcLoggerBeanPostProcessor&quot;&gt;
&lt;property name=&quot;enabled&quot; value=&quot;true&quot; /&gt;
&lt;property name=&quot;dataSourceConfigurations&quot;&gt;
	&lt;list&gt;
 &lt;bean class=&quot;net.sourceforge.jdbclogger.spring.JdbcLoggerDataSourceConfiguration&quot;&gt;
&lt;property name=&quot;dataSourceBeanName&quot; value=&quot;dataSource&quot; /&gt;
&lt;property name=&quot;driverClassNamePropertyName&quot; value=&quot;driverClassName&quot; /&gt;
 &lt;/bean&gt;
 &lt;/list&gt;
 &lt;/property&gt;
&lt;property name=&quot;targetDriverClassNames&quot;&gt;
	&lt;list&gt;
 &lt;value&gt;${jpa.driver}&lt;/value&gt;
 &lt;/list&gt;
 &lt;/property&gt;
 &lt;/bean&gt;
</pre>
<p>3.  Activate logging in the log4j.xml:</p>
<pre class="brush: xml;">

&lt;category name=&quot;net.sourceforge.jdbclogger&quot;&gt;
&lt;priority value=&quot;debug&quot; /&gt;
 &lt;/category&gt;
&lt;category name=&quot;net.sourceforge.jdbclogger.spring&quot;&gt;
&lt;priority value=&quot;error&quot; /&gt;
 &lt;/category&gt;
</pre>
<p>Thats it <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Now you will see logmessages like this:</p>
<p>JdbcLoggerDriver:65 &#8211; Wrapper &#8216;net.sourceforge.jdbclogger.JdbcLoggerDriver&#8217; successfully registed for driver &#8216;com.mysql.jdbc.Driver&#8217;<br />
PreparedStatementWrapper:156 &#8211; Prepared Statement : select softwareca0_.id as id0_, softwareca0_.concurrentVersion as concurre2_0_, softwareca0_.CATEGORY_NAME as CATEGORY3_0_, softwareca0_.PARENT_ID as PARENT4_0_ from SoftwareCategory softwareca0_ where softwareca0_.PARENT_ID is null<br />
StatementWrapper:45 &#8211; Statement : delete from softwarecategory_softwareobject<br />
PreparedStatementWrapper:156 &#8211; Prepared Statement : insert into SoftwareCategory_SoftwareCategory (SoftwareCategory_id, POSITION, children_id) values (&#8216;92&#8242;, &#8216;3&#8242;, &#8216;96&#8242;)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ahoehma.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ahoehma.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ahoehma.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ahoehma.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ahoehma.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ahoehma.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ahoehma.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ahoehma.wordpress.com/174/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ahoehma.wordpress.com/174/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ahoehma.wordpress.com/174/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ahoehma.wordpress.com&blog=1781916&post=174&subd=ahoehma&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ahoehma.wordpress.com/2009/06/03/hibernate-sql-logging-with-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/438fe36eabd9440a47ba9463aa194ac1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ahoehma</media:title>
		</media:content>
	</item>
	</channel>
</rss>