<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en" xml:base="http://www.olivergierke.de/wordpress/wp-atom.php">
	<title type="text">Soul Power</title>
	<subtitle type="text">www.olivergierke.de</subtitle>

	<updated>2011-06-30T21:25:43Z</updated>

	<link rel="alternate" type="text/html" href="http://www.olivergierke.de/wordpress" />
	<id>http://www.olivergierke.de/wordpress/feed/atom/</id>
	

	<generator uri="http://wordpress.org/" version="3.1.4">WordPress</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/olivergierke/soulpower" /><feedburner:info uri="olivergierke/soulpower" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[A JAXB (or rather XJC) odyssey]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/TfCAXhMtL_E/" />
		<id>http://www.olivergierke.de/wordpress/?p=567</id>
		<updated>2011-03-23T11:24:25Z</updated>
		<published>2011-03-23T11:20:41Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="IT" /><category scheme="http://www.olivergierke.de/wordpress" term="coding" /><category scheme="http://www.olivergierke.de/wordpress" term="java" /><category scheme="http://www.olivergierke.de/wordpress" term="jaxb" /><category scheme="http://www.olivergierke.de/wordpress" term="opensource" /><category scheme="http://www.olivergierke.de/wordpress" term="weird stuff" />		<summary type="html"><![CDATA[Working on a customer project the last couple of weeks we decided to use JAXB to unmarshal incoming XML data into Java objects. As that undertaking has caused me quite some trouble I complained on Twitter and received some questions https://twitter.com/bdoughan/status/50183691481268224 comments. As 140 characters are not really able to communicate the issues in detail, [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2011/03/a-jaxb-or-rather-xjc-odyssey/">&lt;p&gt;Working on a customer project the last couple of weeks we decided to use JAXB to unmarshal incoming XML data into Java objects. As that undertaking has caused me quite some trouble I &lt;a href="https://twitter.com/olivergierke/status/50149628041113600"&gt;complained on Twitter&lt;/a&gt; and received &lt;a href="https://twitter.com/billrobertson42/status/50397777724850176"&gt;some&lt;/a&gt; &lt;a href="https://twitter.com/rgladwell/status/50156558830678017"&gt;questions&lt;/a&gt; https://twitter.com/bdoughan/status/50183691481268224 &lt;a href="https://twitter.com/jvanzyl/status/50175081573384193"&gt;comments&lt;/a&gt;. As 140 characters are not really able to communicate the issues in detail, I though I&amp;#8217;d drop a blog post to explain the issues I experienced and the workarounds I took or rather had to take. If there&amp;#8217;s anything I oversaw I&amp;#8217;d be happy to know :).&lt;span id="more-567"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Collection wrapper madness&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;It all starts with an XSD document that is given to a large degree, which means it&amp;#8217;s not entirely set in stone but I actually don&amp;#8217;t want to touch it just to adhere it to the marshalling technology. I had quite good experience with JAXB in other projects we started using it here as well. The unmarshalled objects should be mapped onto our domain objects using Dozer. Here we stumbled above the first issue already. If you have an XML structure that looks like this:&lt;/p&gt;
&lt;pre class="xml" name="code"&gt;
&lt;outer&gt;
  &lt;elements&gt;
    &lt;element&gt;&lt;/element&gt;
    &lt;element&gt;&lt;/element&gt;
  &lt;/elements&gt;
&lt;/outer&gt;
&lt;/pre&gt;
&lt;p&gt;XJC inevitably generates a &lt;code&gt;Elements&lt;/code&gt; wrapper class in the containing element class to contain nothing but the list. So to add an element to the outer element you&amp;#8217;ve got to write following:&lt;/p&gt;
&lt;pre class="java" name="code"&gt;
outer.getElements().getElement().add(new Element());
&lt;/pre&gt;
&lt;p&gt;Concise is different. Even worse, now try mapping this to a domain model that just looks like this:&lt;/p&gt;
&lt;pre class="java" name="code"&gt;
public class Outer {
  private List&lt;Element&gt; elements;
}
&lt;/pre&gt;
&lt;p&gt;Of course you can configure Dozer to map &lt;code&gt;outer.elements.element&lt;/code&gt; from the JAXB classes to &lt;code&gt;outer.elements&lt;/code&gt; in the domain model. This unfortunately fails on the way back, as Dozer cant traverse &lt;code&gt;outer.elements&lt;/code&gt; as &lt;code&gt;elements&lt;/code&gt; field is &lt;code&gt;null&lt;/code&gt; (as it&amp;#8217;s lazily initialized). This issue is probably caused by Dozer as much as by the class structure generated by XJC. But the bottom line is that you&amp;#8217;d have to write custom Dozer converters for &lt;em&gt;each and every&lt;/em&gt; wrapped collection generated by JAXB. The funny thing here is that there is a JAXB annotation &lt;code&gt;@XmlElementWrapper&lt;/code&gt;that allows getting rid of the wrapper class (which would solve quite a few issues listed here). Ironically there&amp;#8217;s no way to configure XJC to generate that &lt;em&gt;except&lt;/em&gt; &lt;a href="http://www.conspicio.dk/blog/bjarne/jaxb-xmlelementwrapper-plugin"&gt;this plugin&lt;/a&gt; which in turn is not available in any Maven Repository out there. &lt;/p&gt;
&lt;p&gt;&lt;b&gt;If it&amp;#8217;s not in a Maven repository, it doesn&amp;#8217;t exist&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;In the REST community there&amp;#8217;s a proverb saying &amp;#8220;If you can&amp;#8217;t link to it, it doesn&amp;#8217;t exist&amp;#8221;. Bringing that into Java Open Source software it&amp;#8217;s &lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&amp;#8220;If it&amp;#8217;s not available in a Maven repository, it doesn&amp;#8217;t exist&amp;#8221;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt; or the more strict version &lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&amp;#8220;If it&amp;#8217;s not in Maven central, it doesn&amp;#8217;t exist&amp;#8221;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;. Anyway…&lt;/p&gt;
&lt;p&gt;&lt;b&gt;JavaBean spec? Who cares…&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Requirements changed a little and we decided to persist the JAXB generated classes directly. We had chosen a Spring Data Mongo based backend which can persist plain Java objects into JSON documents and in turn pipe &amp;#8216;em into a Mongo database. The only requirement is that the classes align to the JavaBean spec by default. Of course Spring Data Mongo has mapping facilities via annotations but as the classes persisted are generated ones, I can&amp;#8217;t or don&amp;#8217;t want to touch them. Now guess what? XJC does &lt;em&gt;not&lt;/em&gt; generate valid JavaBeans by default. It generates &lt;code&gt;Boolean isFoo()&lt;/code&gt; although the JavaBean spec says the &lt;code&gt;is&lt;/code&gt; prefix is only allowed for primitive &lt;/code&gt;boolean&lt;/code&gt;s (thanks to &lt;a href="http://twitter.com/#!/tOMPSON"&gt;Thomas Einwaller&lt;/a&gt; for pointing me to &lt;a href="http://www.mojavelinux.com/blog/archives/2006/09/the_great_jaxb_api_blunder/index.php"&gt;this&lt;/a&gt;). Sidenote: &lt;code&gt;java.beans.Inspector&lt;/code&gt; thus does not consider the &lt;code&gt;isFo()o&lt;/code&gt; method as valid read method in the &lt;code&gt;PropertyDescriptor&lt;/code&gt; instances returned. Nevertheless you can manually instantiate a &lt;code&gt;PropertyDescriptor&lt;/code&gt; that the in turn contains the &lt;code&gt;isFoo()&lt;/code&gt; method as read method. Consistency? See more on that in &lt;a href="https://jira.springsource.org/browse/SPR-8071"&gt;the ticket&lt;/a&gt; I filed against Spring as we're using it's bean introspection mechanism that could mitigate this inconsistency.&lt;/p&gt;
&lt;p&gt;This time there's no need use an XJC plugin to get this working as XJC. It simply supports a &lt;code&gt;-enableIntrospection&lt;/code&gt; flag that you can pipe to XJC to let it generate spec compliant &lt;code&gt;Boolean getFoo()&lt;/code&gt; methods for the &lt;code&gt;Boolean&lt;/code&gt; properties. Generally I rather think the spec is broken here as from a beans model perspective it shouldn't make a difference whether I am using &lt;code&gt;boolean&lt;/code&gt; or &lt;code&gt;Boolean&lt;/code&gt;. Regarding XJC I am not sure if I am the only one who raises his eyebrow using a flag on a software that effectively says "Please do it right".&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Subtleties&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Something not entirely related to the JavaBean spec but close enough to mention it here is that XJC generates inconsistent field accessor pairs regarding naming. In the XML we had an element similar to &lt;code&gt;FOOBar&lt;/code&gt;. The class containing a field now looks something like this:&lt;/p&gt;
&lt;pre class="java" name="code"&gt;public class Outer {
  private FOOBar fooBar;

  public FOOBar getFOOBar() {

  }
}&lt;/pre&gt;
&lt;p&gt;Notice the difference? For the field the first part is lowercased entirely, whereas the method name takes the element name as is. Crucial thing here is that you can't really apply the "&lt;code&gt;get&lt;/code&gt;-plus-uppercase-first-letter-plus-rest" heuristics to find the getter for a field or vice versa. This especially becomes important if you want to use field injection for properties. Once again, there's a plugin to fix that (do you really want to use software that uses plugins to fix bugs?), which unfortunately is not available via a Maven repository. So finally we renamed the element to &lt;code&gt;FooBar&lt;/code&gt; to get this working. No problem in general but I generally don't like the fact that my model (however questionable the naming structure might be here) has to be tweaked just to get the technology work right.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;JAXB2 Commons&lt;/b&gt;&lt;br /&gt;
There are a few really great XJC plugins flying around that allow generating copy constructors, &lt;code&gt;equals(…)&lt;/code&gt; and &lt;code&gt;hashCode(…)&lt;/code&gt; methods and the like. Unfortunately googling them is quite a pain as the most popular result, the &lt;a href="http://java.net/projects/jaxb2-commons/pages/Home"&gt;official Oracle page&lt;/a&gt; contains mostly dead links (try everything but the JAXB2 Basic) plugin.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
Maybe I am a bit spoilt but this odyssey leaves me with the impression that esp. XJC is a kludgy piece of software that only works correctly or well enough to be usable if you use quite a handful of plugins. As a lot of them are not available in Maven repositories the average Maven user (which I don't consider to be an exotic thing nowadays) can't use - at least not effectively. This impression was completely contradicting my previous experiences with JAXB, although I have to admit that these former projects rather used the annotations directly and not XJC. So it seems it's rather XJC that needs some serious polishing. Is there a JSR for JAXB 3, already? ;)&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/TfCAXhMtL_E" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2011/03/a-jaxb-or-rather-xjc-odyssey/#comments" thr:count="6" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2011/03/a-jaxb-or-rather-xjc-odyssey/feed/atom/" thr:count="6" />
		<thr:total>6</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2011/03/a-jaxb-or-rather-xjc-odyssey/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[Spring, logging and JMX]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/t25UN1vwrKo/" />
		<id>http://www.olivergierke.de/wordpress/?p=541</id>
		<updated>2010-10-01T14:02:55Z</updated>
		<published>2010-10-01T14:02:55Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="Allgemein" /><category scheme="http://www.olivergierke.de/wordpress" term="IT" /><category scheme="http://www.olivergierke.de/wordpress" term="best practices" /><category scheme="http://www.olivergierke.de/wordpress" term="coding" /><category scheme="http://www.olivergierke.de/wordpress" term="jmx" /><category scheme="http://www.olivergierke.de/wordpress" term="spring" />		<summary type="html"><![CDATA[Pretty much every application out in the wild is using logging to some extend. As applications tend to have bugs (yes, yours as well) it&#8217;s a common requirement to alter log levels at runtime. As JMX (Java Management Extensions) is a standard to monitor and manage applications it seems to be a reasonable approach to [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2010/10/spring-logging-and-jmx/">&lt;p&gt;Pretty much every application out in the wild is using logging to some extend. As applications tend to have bugs (yes, yours as well) it&amp;#8217;s a common requirement to alter log levels at runtime. As JMX (Java Management Extensions) is a standard to monitor and manage applications it seems to be a reasonable approach to expose the loggers used in an application via JMX to allow tuning of log levels via a JMX client like jconsole. So let&amp;#8217;s take a look on how you enable JMX with Spring&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;context:mbean-server /&amp;gt;&lt;br /&gt;
&amp;lt;context:mbean-export /&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The first element from the context namespace sets up a JMX server so that MBeans can be registered. The second element activates automatic export of all Spring beans the either leverage Spring JMX support (annotation based) or Spring beans that satisfy the JMX naming scheme (a class implementing an interface named &lt;code&gt;${classname}MBean&lt;/code&gt;). Fortunately Log4J ships with a &lt;code&gt;LoggerDynamicMBean&lt;/code&gt; that exports a &lt;code&gt;Logger&lt;/code&gt; instance to the JMX infrastructure. It&amp;#8217;s API is not really built with dependency injection in mind but due to the flexibility of the Spring XML configuration language we could register this MBean as follows:&lt;/p&gt;
&lt;pre name="code" class="xml"&gt;&lt;bean class="org.apache.log4j.jmx.LoggerDynamicMBean"&gt;
  &lt;constructor-arg&gt;
    &lt;bean class="org.apache.log4j.Logger"
      factory-method="getLogger"&gt;
      &lt;constructor-arg
        value="org.springframework.jmx" /&gt;
    &lt;/bean&gt;
  &lt;/constructor-arg&gt;
&lt;/bean&gt;&lt;/pre&gt;
&lt;p&gt;Running this in combination with the XML snippet above now exposes the logger for &lt;code&gt;org.springframework.jmx&lt;/code&gt; as JMX MBean.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;XML Hell? Go make it clear and nice!&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Declaring the MBean for a single logger requires quite an amount of XML and is boilerplate to a large degree. The two things that are unique in this case is that we want to expose a Log4J logger and the logger name of org.springframework.jmx. So what if we could expose the logger with something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;jmx:logger type="Log4J"
  name="org.springframework.jmx" /&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can! I&amp;#8217;ve created a small &lt;a href="http://github.com/olivergierke/spring-jmx-namespace"&gt;sample project&lt;/a&gt; project containing a custom JMX namespace and put it up on Github. The README file contains instructions how to play around with the Sample class, altering the log level via jconsole and see results in the console output. Right now it&amp;#8217;s pretty much just a proof of concept and could be improved in a few corners. We should support other logging libraries and we could transparently register &lt;code&gt;&lt;context:mbean-server /&gt;&lt;/code&gt; and &lt;code&gt;&lt;context:mbean-export /&gt;&lt;/code&gt; whcih is not the case currently. Feel free to suggest or add extensions!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/t25UN1vwrKo" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2010/10/spring-logging-and-jmx/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2010/10/spring-logging-and-jmx/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2010/10/spring-logging-and-jmx/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[Enabling Hibernate criteria query statistics with AspectJ]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/_k0shQjgTPg/" />
		<id>http://www.olivergierke.de/wordpress/?p=532</id>
		<updated>2011-03-23T11:23:27Z</updated>
		<published>2010-09-15T10:59:20Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="IT" /><category scheme="http://www.olivergierke.de/wordpress" term="aop" /><category scheme="http://www.olivergierke.de/wordpress" term="aspectj" /><category scheme="http://www.olivergierke.de/wordpress" term="coding" /><category scheme="http://www.olivergierke.de/wordpress" term="criteria api" /><category scheme="http://www.olivergierke.de/wordpress" term="hibernate" /><category scheme="http://www.olivergierke.de/wordpress" term="java" />		<summary type="html"><![CDATA[In the #java.de IRC channel someone pointed me to this request for enhancement in Hibernate recently. The bottom line here is that Hibernate&#8217;s statistics feature that can be used to capture persistence metrics (information about query executions and execution times and so on) does not include queries triggered through using the criteria API. This is [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2010/09/enabling-hibernate-critera-query-statistics-with-aspectj/">&lt;p&gt;In the #java.de IRC channel someone pointed me to this &lt;a title="Hibernate Issue Tracker: Capture statistics for Criteria queries, too" href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-3452"&gt;request for enhancement&lt;/a&gt; in Hibernate recently. The bottom line here is that Hibernate&amp;#8217;s statistics feature that can be used to capture persistence metrics (information about query executions and execution times and so on) does not include queries triggered through using the criteria API.&lt;/p&gt;
&lt;p&gt;This is quite a a reasonable request for enhancement in my opinion and it&amp;#8217;s quite surprising that the ticket has been open for over 2 years now, especially as the solution seems to be simply adding a method to &lt;code&gt;CriteriaLoader&lt;/code&gt; class, as Chuck May points out.  So supposed you want to use tis feature &lt;em&gt;now&lt;/em&gt;. The only option seems to be patching Hibernate (sort of doable), building it (a huge magnitude more complex &amp;#8211; no offense, building Spring is not trivial either) and the use and maintain that patched version over further releases. Isn&amp;#8217;t there another way to get that feature into Hibernate? Of course there is… AspectJ.&lt;span id="more-532"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;As the fix seems to be simply adding a method to an existing class we can leverage AspectJ inter-type declarations to add this special method from the outside. Here&amp;#8217;s the aspect code:&lt;/p&gt;
&lt;pre name="code" class="java"&gt;public privileged aspect CriteriaStatisticsAspect {
  public String CriteriaLoader.getQueryIdentifier() {
    return "[CRITERIA] " + getSQLString();
  }
}&lt;/pre&gt;
&lt;p&gt;It&amp;#8217;s pretty easy to understand I think as the method declaration only slightly differs from a normal Java one (no pun intended). You actually only have to explicitly mention the type you want to add the method to. To weave this aspect into Hibernate you simply add the &lt;a title="Maven AspectJ plugin" href="http://mojo.codehaus.org/aspectj-maven-plugin/"&gt;Maven AspectJ plugin&lt;/a&gt; to your &lt;code&gt;pom.xml&lt;/code&gt; and tell it to consider the Hibernate JARs too by adding a &lt;code&gt;weaveDependencies&lt;/code&gt; block to the configuration section of the plugin.&lt;/p&gt;
&lt;p&gt;To ease the burden of getting started with this approach I have uploaded the &lt;a title="Sample code at Github" href="http://github.com/olivergierke/hibernate-criteria-statistics"&gt;sample code&lt;/a&gt; to Github, also containing a test case to demonstrate this actually works. Upgrading to another Hibernate versions should work seamlessly as the aspect gets woven into the never version then. As soon as the feature gets actually implemented (let&amp;#8217;s hope it won&amp;#8217;t take another two years ;) simply throw away the aspect.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/_k0shQjgTPg" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2010/09/enabling-hibernate-critera-query-statistics-with-aspectj/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2010/09/enabling-hibernate-critera-query-statistics-with-aspectj/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2010/09/enabling-hibernate-critera-query-statistics-with-aspectj/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[Conference autumn 2010]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/6Mso86cW5s0/" />
		<id>http://www.olivergierke.de/wordpress/?p=527</id>
		<updated>2010-09-10T12:37:21Z</updated>
		<published>2010-09-10T12:37:21Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="IT" /><category scheme="http://www.olivergierke.de/wordpress" term="devoxx" /><category scheme="http://www.olivergierke.de/wordpress" term="events" /><category scheme="http://www.olivergierke.de/wordpress" term="hades" /><category scheme="http://www.olivergierke.de/wordpress" term="java" /><category scheme="http://www.olivergierke.de/wordpress" term="java user group" /><category scheme="http://www.olivergierke.de/wordpress" term="talks" />		<summary type="html"><![CDATA[As summer&#8217;s fading out more or less, it&#8217;s time to take a look at upcoming times. Autumn is  usually quite packed with conferences and this seems to continue this year. I&#8217;ll kick off my conference autumn by speaking at WebAppDays in Düsseldorf (Sept. 27th/28th) presenting Roo as rapid java application development framework as well as [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2010/09/conference-autumn-2010/">&lt;p&gt;As summer&amp;#8217;s fading out more or less, it&amp;#8217;s time to take a look at upcoming times. Autumn is  usually quite packed with conferences and this seems to continue this year.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ll kick off my conference autumn by speaking at &lt;a title="WebAppDays" href="http://www.webappdays.de/"&gt;WebAppDays&lt;/a&gt; in Düsseldorf (Sept. 27th/28th) presenting &lt;a title="Spring Roo" href="http://www.springsource.org/roo"&gt;Roo&lt;/a&gt; as rapid java application development framework as well as giving an overview about &lt;a title="tcServer product homepage" href="http://www.springsource.com/products/tcserver"&gt;tcServer&lt;/a&gt;, the SpringSource commercial edition of &lt;a title="Tomcat project homepage" href="http://tomcat.apache.org/"&gt;Tomcat&lt;/a&gt;. To not make this a marketing talk entirely, I will concentrate on how &lt;em&gt;developers&lt;/em&gt; can benefit from tcServer usage during development and in production.&lt;/p&gt;
&lt;p&gt;Next stop for me the is &lt;a title="GearConf conference homepage" href="http://gearconf.com/"&gt;GearConf&lt;/a&gt;, Düsseldorf (Oct. 11th/12th), a conference dedicated to the more soft topics of software development like processes and teams. This year I&amp;#8217;ll be talking about &lt;a title="Mylyn project homepage" href="http://www.eclipse.org/mylyn/"&gt;Mylyn&lt;/a&gt; and how it can help developers to be more productive and ease context switches.&lt;/p&gt;
&lt;p&gt;If you register quickly there&amp;#8217;s still the chance to get discount for both of these conferences. As they are rather small ones, it&amp;#8217;s quite intensive as hallroom conversations take place pretty much everytime and everywhere so that the knowledge exchange rate is typically quite high.&lt;/p&gt;
&lt;p&gt;The main event this autum of course is &lt;a title="Devoxx homepage" href="http://www.devoxx.com"&gt;Devoxx&lt;/a&gt; 2010, Antwerp. Personally I&amp;#8217;ll be holding the Mylyn talk there but there&amp;#8217;s a ton of other speakers and talks to check out. As &lt;a title="SpringSource homepage" href="http://www.springsource.com"&gt;SpringSource&lt;/a&gt; is also official sponsor of the app a lot of my colleagues will also speak there, e.g &lt;a title="Jürgen on Twitter" href="http://twitter.com/springjuergen"&gt;Jürgen Höller &lt;/a&gt;on &lt;a title="Spring 3.1 themes and trends" href="http://www.devoxx.com/display/Devoxx2K10/Spring+3.1+-+Themes+and+Trends"&gt;Spring 3.1&lt;/a&gt;, &lt;a title="Ben Alex on Twitter" href="http://twitter.com/benalexau"&gt;Ben Alex&lt;/a&gt; on &lt;a title="Ben Alex on Spring Roo" href="http://www.devoxx.com/display/Devoxx2K10/Extreme+Productivity+with+Spring+Roo"&gt;Roo&lt;/a&gt;,&lt;a title="Christian Dupuis on Twitter" href="http://twitter.com/cdupuis"&gt; Christian Dupuis&lt;/a&gt; on tooling for &lt;a title="Talk on Spring tools" href="http://www.devoxx.com/display/Devoxx2K10/Spring+Developer+Tools+to+push+your+Productivity"&gt;Spring&lt;/a&gt; and &lt;a title="Talk on Groovy/Grails" href="http://www.devoxx.com/display/Devoxx2K10/Groovy+Grails+Development+in+Eclipse"&gt;Grails&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Right in between those events I will promote upcoming Hades 2.0 release at &lt;a title="Talk @ JUG Cologne" href="http://87.230.78.21:8080/display/jugc/2010.11.08+Agile+in+a+Year+und+Hades"&gt;JUG Cologne Nov. 8th&lt;/a&gt;. Chances are high that we have published the release then already. I am currently speaking to a few other JUGs as well, so you can be sure Hades will be near your place, too. :)&lt;/p&gt;
&lt;p&gt;Anyway, I&amp;#8217;m really looking forward to these events. Hope to see a lot of familiar faces and hopefully also some new ones (chances are not bad). Feel free to get in touch and let&amp;#8217;s have a beer (malt for me, whatever you like for you :)&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/6Mso86cW5s0" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2010/09/conference-autumn-2010/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2010/09/conference-autumn-2010/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2010/09/conference-autumn-2010/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[DDD Specifications with Hades]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/agJuwZpZKQE/" />
		<id>http://www.olivergierke.de/wordpress/?p=513</id>
		<updated>2010-07-15T23:03:46Z</updated>
		<published>2010-07-15T23:03:46Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="Hades" /><category scheme="http://www.olivergierke.de/wordpress" term="coding" /><category scheme="http://www.olivergierke.de/wordpress" term="domain driven design" /><category scheme="http://www.olivergierke.de/wordpress" term="events" /><category scheme="http://www.olivergierke.de/wordpress" term="hades" /><category scheme="http://www.olivergierke.de/wordpress" term="java" /><category scheme="http://www.olivergierke.de/wordpress" term="opensource" />		<summary type="html"><![CDATA[Two weeks ago, I attended Java Forum Stuttgart, a really nice one-day conference to hear interesting talks, meet fellow developers and colleagues. The first talk I attended was held by Adrian Hummel and Mischa Kölliker entitled Rich domain model with JPA 2.0. As I am currently working on the final features for Hades 2.0 which [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2010/07/ddd-specifications-with-hades/">&lt;p&gt;Two weeks ago, I attended &lt;a href="http://www.java-forum-stuttgart.de" target="_blank" title="Java Forum Stuttgart"&gt;Java Forum Stuttgart&lt;/a&gt;, a really nice one-day conference to hear interesting talks, meet fellow developers and colleagues. The first talk I attended was held by &lt;a href="http://adrianhummel.wordpress.com/" target="_blank" title="Adrian Hummel's blog"&gt;Adrian Hummel&lt;/a&gt; and Mischa Kölliker entitled &lt;a href="http://www.java-forum-stuttgart.de/abstracts.html#D1" target="_blank" title="Rich domain model with JPA 2.0"&gt;Rich domain model with JPA 2.0&lt;/a&gt;. As I am currently working on the final features for Hades 2.0 which will be based on JPA 2.0, I was eager to see what they were about to present.&lt;span id="more-513"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;One part of their talk was dealing with the specifications concept of the &lt;a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?ie=UTF8&amp;#038;s=books-intl-de&amp;#038;qid=1279234366&amp;#038;sr=8-1" target="_blank" title="Domain Driven Design @ Amazon"&gt;Domain Driven Design&lt;/a&gt; book by Eric Evans. &lt;code&gt;Specification&lt;/code&gt;s are an abstraction over a statement or requirement you can formulate for an entity. Each of the specifications you can define evaluates to a &lt;code&gt;boolean&lt;/code&gt;, so it can be regarded as predicate over the entity. The example Adrian gave in his talk (and also in a &lt;a href="http://adrianhummel.wordpress.com/2010/07/02/composed-specifications-using-jpa-2-0/" target="_blank" title="Adrian Hummel on Specifications"&gt;blogpost&lt;/a&gt; he dropped a few days later) is a soccer player, who can be characterized as &amp;#8220;fair player&amp;#8221; or as &amp;#8220;bonus eligible&amp;#8221;.&lt;/p&gt;
&lt;p&gt;JPA 2.0 introduces a criteria API, that effectively allows to define queries via a more or less typesafe API. So the typical code you write using this API looks as follows (code originally coined by Adrian):&lt;/p&gt;
&lt;pre name="code" class="java"&gt;CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery&amp;lt;Player&amp;gt; q = cb.createQuery(Player.class);
Root&amp;lt;Player&amp;gt; player = q.from(Player.class);

q.where(/** Build your where clause here **/);

return em.createQuery(q).getResultList();&lt;/pre&gt;
&lt;p&gt;As you see there&amp;#8217;s a few lines of boilerplate code that works with the domain class. The part that actually varies from query to query is the where clause you hand to the &lt;code&gt;q.where(…)&lt;/code&gt; method. What Adrian and Mischa now proposed is introducing a &lt;code&gt;Specification&amp;lt;T&amp;gt;&lt;/code&gt; interface that simply provides a callback method that gets the &lt;code&gt;CriteriaBuilder&lt;/code&gt;, &lt;code&gt;CriteriaQuery&amp;lt;T&amp;gt;&lt;/code&gt; and &lt;code&gt;Root&amp;lt;T&amp;gt;&lt;/code&gt; and reduces that to a JPA Predicate which can be handed to the &lt;code&gt;q.where(…)&lt;/code&gt; method then (code originally coined by Adrian):&lt;/p&gt;
&lt;pre name="code" class="java"&gt;public interface Specification&amp;lt;T&amp;gt; {

 Predicate toPredicate(CriteriaBuilder cb,
   CriteryQuery&amp;lt;T&amp;gt; q, Root&amp;lt;T&amp;gt; root);
}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Specifications in Hades&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To make this available in Hades we simpy add a method &lt;code&gt;readAll(Specification&amp;lt;T&amp;gt; spec)&lt;/code&gt; to &lt;code&gt;GenericDao&lt;/code&gt; interface and &lt;code&gt;GenericJpaDao&lt;/code&gt; implementation and implement it as follows:&lt;/p&gt;
&lt;pre name="code" class="java"&gt;public List&amp;lt;T&amp;gt; readAll(Specification&amp;lt;T&amp;gt; spec) {
  CriteriaBuilder cb = em.getCriteriaBuilder();
  CriteriaQuery&amp;lt;T&amp;gt; q = cb.createQuery(getDomainClass());
  Root&amp;lt;T&amp;gt; player = q.from(getDomainClass());

  q.where(spec.toPredicate(cb, q, root);

  return em.createQuery(q).getResultList();
}&lt;/pre&gt;
&lt;p&gt;So what this gains you is a possibility to simply add new &lt;code&gt;Specification&lt;/code&gt; implementations and thus &amp;#8220;extend&amp;#8221; the DAO without the need to add finders e.g.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;One more thing&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The really cool part about the &lt;code&gt;Specification&lt;/code&gt;s is, that &amp;#8211; as you can concatenate JPA &lt;code&gt;Predicate&lt;/code&gt;s with &lt;code&gt;and&lt;/code&gt; and &lt;code&gt;or&lt;/code&gt; &amp;#8211; you can do this with some minor effort on the &lt;code&gt;Specification&lt;/code&gt;s, too. I added a small class that provides some syntactical sugar to make something like this possible:&lt;/p&gt;
&lt;pre name="code" class="java"&gt;playerDao.readBySpecification(
  where(isFair()).and(isEligibleForBonus()));&lt;/pre&gt;
&lt;p&gt;This probably needs some explaination. First, &lt;code&gt;isFair()&lt;/code&gt; and &lt;code&gt;isEligibleForBonus()&lt;/code&gt; are static methods on a (for example) &lt;code&gt;PlayerSpecifications&lt;/code&gt; class that return a &lt;code&gt;Specification&lt;/code&gt; instance creating the JPA &lt;code&gt;Predicate&lt;/code&gt; instance. The &lt;code&gt;where(…)&lt;/code&gt; method is also a static one on a helper class that pretty much returns itself, implements &lt;code&gt;Specification&lt;/code&gt; in turn and and provides the concatenation methods to chain &lt;code&gt;Specification&lt;/code&gt;s and build new &lt;code&gt;Specification&lt;/code&gt;s on the fly. Thus you can easily implement atomic predicates for the entity and build more complex expression from it &amp;#8211; a really cool complement to the finder methods already available in Hades. The feature will be available in upcoming RC3 of Hades 2.0 and can already be used with the current snapshots.&lt;/p&gt;
&lt;p&gt;A big thank you to Adrian and Mischa for a huge part of this new feature =).&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/agJuwZpZKQE" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2010/07/ddd-specifications-with-hades/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2010/07/ddd-specifications-with-hades/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2010/07/ddd-specifications-with-hades/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[Hades &#8211; standing on the shoulders of giants]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/q680pum3Dyk/" />
		<id>http://www.olivergierke.de/wordpress/?p=500</id>
		<updated>2010-07-01T18:56:02Z</updated>
		<published>2010-06-30T19:40:18Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="Hades" /><category scheme="http://www.olivergierke.de/wordpress" term="IT" /><category scheme="http://www.olivergierke.de/wordpress" term="aop" /><category scheme="http://www.olivergierke.de/wordpress" term="coding" /><category scheme="http://www.olivergierke.de/wordpress" term="hades" /><category scheme="http://www.olivergierke.de/wordpress" term="java" /><category scheme="http://www.olivergierke.de/wordpress" term="jpa" /><category scheme="http://www.olivergierke.de/wordpress" term="opensource" /><category scheme="http://www.olivergierke.de/wordpress" term="spring" />		<summary type="html"><![CDATA[In the last few days I have been working on a feature request of Hades that has been after me for quite a long time. Hades has always had built in support for auditing entities, which means it captured the current user of the application and set it as the creator or modifier on the [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2010/06/hades-standing-on-the-shoulders-of-giants/">&lt;p&gt;In the last few days I have been working on a feature request of Hades that has been after me for quite a long time. Hades has always had built in support for auditing entities, which means it captured the current user of the application and set it as the creator or modifier on the entity whenever you called save on a Hades DAO. This is based on AOP, has always been a nice showcase of AOP applied, hopefully served a few users quite well. So far so good. Unfortunately the way it was implemented had two serious drawbacks:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;It only works if you call &lt;code&gt;MyDao.save(…)&lt;/code&gt; explicitly&lt;/li&gt;
&lt;li&gt;It only works for the root entity you persist, not transitive ones.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;These drawbacks have caused Will Jaynes to open up a &lt;a href="http://redmine.synyx.org/issues/53" title="Enable more than just root entity auditing"  target="_blank"&gt;ticket&lt;/a&gt; over a year ago already and I have been thinking about that issue from time to time, sometimes more deeply, sometimes just remembered it was still open. Finally I came up with a solution that not only fixes the two points mentioned above but also acts as a quite nice example of how powerful Spring as a toolbox can be, especially for framework or library developers. Here&amp;#8217;s the story…&lt;span id="more-500"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The right tool for the job&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Actually, implementing auditing with AOP was not the right choice in the first place. Well, it&amp;#8217;s not that AOP in general is the wrong hammer for this nail but rather how we applied it. Auditing based on a pointcut targeting a repository method is plain wrong if we deal with OR mappers, period. So I do not consider myself extraordinarily stupid so you and I might wonder what took me down that road.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Entity listeners&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The core abstraction for reacting on lifecycle events for entities in JPA are so called entity listeners. You can either annotate the entity itself with annotations like &lt;code&gt;@PrePersist&lt;/code&gt; or &lt;code&gt;@PreUpdate&lt;/code&gt; or use a dedicated class with annotated methods in case you want to implement common hooks you might want to apply to a common set of classes. You activate those entity listeners by either annotating the entity with &lt;code&gt;@EntityListeners&lt;/code&gt; or configure them in your &lt;code&gt;orm.xml&lt;/code&gt;. The reason they never seemed suitable for me is that they get instantiated by the JPA provider and thus &amp;#8211; by default &amp;#8211; lack any means of injecting dependencies into them (the &lt;code&gt;AuditorAware&lt;/code&gt; instance knowing who is the current user in our case).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;@Configurable&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Fortunately Spring offers injecting dependencies into classes created with &lt;code&gt;new&lt;/code&gt; by adding an &lt;code&gt;@Configurable&lt;/code&gt; to the class to be instantiated. You simply have to get a Spring aspect woven into that class then and activate in your apps XML config and Spring will intercept the instantiation of that class and either autowire dependencies or use a blueprint prototype bean to determine what has to be wired how. (For details see a &lt;a title="Using Spring's @Configurable in three easy steps" href="http://www.olivergierke.de/wordpress/2009/05/using-springs-configurable-in-three-easy-steps/" target="_blank"&gt;former blogpost&lt;/a&gt; or the &lt;a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-atconfigurable"&gt;reference documentation&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;So let&amp;#8217;s recap what we have here: I let the aspect be compiled into my &lt;code&gt;AuditingEntityListener&lt;/code&gt; and activate  as well as a prototype bean of the listener getting a &lt;code&gt;StubAuditorAware&lt;/code&gt; injected in my integration tests config file. Hm, doesn&amp;#8217;t work… What&amp;#8217;s wrong? Here&amp;#8217;s the critical part of the reference doc.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Instances of &lt;code&gt;@Configurable&lt;/code&gt; objects created before the aspect has been configured will result in a warning being issued to the log and no configuration of the object taking place. An example might be a bean in the Spring configuration that creates domain objects when it is initialized by Spring. In this case you can use the &lt;code&gt;depends-on&lt;/code&gt; bean attribute to manually specify that the bean depends on the configuration aspect.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Okay, it seems the aspect is not yet active when my &lt;code&gt;LocalContainerEntityManagerFactoryBean&lt;/code&gt; gets instantiated which in turn instantiates my entity listener. The docs recommend (no pun intended) to emphasize the order of the beans by adding a &lt;code&gt;depends-on&lt;/code&gt; attribute to the bean that manually instantiates objects (the &lt;code&gt;EntityManagerFactoryBean&lt;/code&gt; in our case). First: what bean to depend on since spring-configured has no id. Ah, it turns out Spring registers the aspect under &lt;code&gt;org.springframework.context.config.internalBeanConfigurerAspect&lt;/code&gt;. So I&amp;#8217;d essentially need something like this to make sure the &lt;code&gt;EntityManagerFactory&lt;/code&gt; already sees the DI aspect:&lt;/p&gt;
&lt;pre name="code" class="xml"&gt;

&lt;context:spring-configured /&gt;

&lt;bean class="….LocalContainerEntitiyManagerFacotryBean"
  depends-on="org.springframework.context.config.internalBeanConfigurerAspect"/&gt;
&lt;/pre&gt;
&lt;p&gt;Well, wait… of course I could document that this was necessary but that would bloat Hades user&amp;#8217;s infrastructure configuration, expose Spring internal bean names and make things unnecessary complex.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Spring container hooks &amp;#8211; BeanFactoryPostProcessor&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Okay, so what we essentially need to do is transparently add a &lt;code&gt;depends-on="org.springframework.context.config.internalBeanConfigurerAspect"&lt;/code&gt; to the chosen &lt;code&gt;EntityManagerFactoryBean&lt;/code&gt; bean definition. Fortunately we can do this programatically by using one of the Spring container hooks, the &lt;code&gt;BeanFactoryPostProcessor&lt;/code&gt;. So I simply implemented a &lt;code&gt;AuditingBeanFactoryPostProcessor&lt;/code&gt; that transparently adds the (additional) &lt;code&gt;depends-on&lt;/code&gt; to bean definitions that create an &lt;code&gt;EntityManagerFactory&lt;/code&gt;. So the benefit here is that we can leave other user defined beans untouched. Let&amp;#8217;s take a look on what we have to configure on the Spring side to get things up and running:&lt;/p&gt;
&lt;pre name="code" class="xml"&gt;
&lt;context:spring-configured /&gt;
&lt;bean class="….AuditingBeanFactoryPostProcessor" /&gt;

&lt;bean class="….auditing.support.AuditingEntityListener"&gt;
&lt;property value="auditorAware" ref="auditorAware" /&gt;
&lt;/bean&gt;

&lt;bean id="auditorAware" class="com.acme.MyAuditorAwareImpl" /&gt;
&lt;/pre&gt;
&lt;p&gt;As you can see, there&amp;#8217;s a lot of boilerplate XML config here. The only thing really custom is the delaration of the &lt;code&gt;MyAuditorAwareImpl&lt;/code&gt;. Now guess what? There&amp;#8217;s some Spring for that…  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Spring namespaces&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As you probably already know (as you might have used Hades already) Spring supports the implementation of custom XML namespaces since 2.5. We already implemented the &lt;code&gt;dao-config&lt;/code&gt; element in the Hades namespace so why not add one to activate auditing? So here&amp;#8217;s what we end up with:&lt;/p&gt;
&lt;pre name="code" class="xml"&gt;&lt;hades:auditing auditor-aware-ref="auditorAware" /&gt;

&lt;bean id="auditorAware"
  class="com.acme.MyAuditorAwareImpl" /&gt;&lt;/pre&gt;
&lt;p&gt;Quite neat, isn&amp;#8217;t it? So let&amp;#8217;s summarize what we have gained from the plain auditing feature view:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We get transparent auditing on all JPA managed entities, whether they are the root entity or a transitive one.&lt;/li&gt;
&lt;li&gt;No need to call &lt;code&gt;MyDao.save(…)&lt;/code&gt; to trigger auditing.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Nice, feature completed ;). Now let&amp;#8217;s take another step back an reflect what brought us there:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Spring&amp;#8217;s ability to inject dependencies into objects instantiated with &lt;code&gt;new&lt;/code&gt; through &lt;code&gt;@Configurable&lt;/code&gt; and AOP.&lt;/li&gt;
&lt;li&gt;Prevented custom configuration spread around into other beans thorugh Spring&amp;#8217;s &lt;code&gt;BeanFactoryPostProcessor&lt;/code&gt; container hook.&lt;/li&gt;
&lt;li&gt;Reduced the amount of configuration required through a custom namespace to hand an expressive concise configuration language (in our case in form of a single XML element ;) to the user instead of a generic verbose one.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Enough praising here, enjoy auditing with Hades! =)&lt;/p&gt;
&lt;p&gt;P.S.: In case you want to take a glance at the sources checkout the &lt;a href="http://redmine.synyx.org/projects/hades/repository/revisions/11827"&gt;commits&lt;/a&gt; I&amp;#8217;ve done for the &lt;a href="http://redmine.synyx.org/issues/53" title="Enable more than just root entity auditing"&gt;feature request&lt;/a&gt;.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/q680pum3Dyk" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2010/06/hades-standing-on-the-shoulders-of-giants/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2010/06/hades-standing-on-the-shoulders-of-giants/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2010/06/hades-standing-on-the-shoulders-of-giants/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[Hades 2.0.0.RC2 introduces transactional DAOs]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/pQgDdWkjM7I/" />
		<id>http://www.olivergierke.de/wordpress/?p=495</id>
		<updated>2010-06-22T19:11:24Z</updated>
		<published>2010-06-22T19:11:24Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="Hades" /><category scheme="http://www.olivergierke.de/wordpress" term="hades" /><category scheme="http://www.olivergierke.de/wordpress" term="opensource" /><category scheme="http://www.olivergierke.de/wordpress" term="releases" />		<summary type="html"><![CDATA[Our latest Hades release of the 2.0 branch is introducing transactionality of DAO instances as main new feature. Of course you can read up the reference documentation for some general guidelines but I want to use the chance to give a more detailed look into why we introduce this and how some details work. These [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2010/06/hades-2-0-0-rc2-introduces-transactional-daos/">&lt;p&gt;Our latest Hades &lt;a title="Hades release announcement" href="http://redmine.synyx.org/news/18" target="_blank"&gt;release&lt;/a&gt; of the 2.0 branch is introducing transactionality of DAO instances as main new feature. Of course you can read up the reference documentation for some general guidelines but I want to use the chance to give a more detailed look into why we introduce this and how some details work.&lt;span id="more-495"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;These days, some kind of back-to-the-basics approach regarding architecture layering is widely accepted as best practices. Thus you don&amp;#8217;t want to introduce a layer just because of some merely technical needs. A typical candidate layer for being obsolete is the service layer. Especially in web applications where you pretty much store entities that are equipped with rich behavior themselves the service layer is quite an artificial one that only demarcates transactions but then delegates to the underlying data access layer. Using Hades in such an application you had needed the additional transaction demarcation somewhere as it didn&amp;#8217;t deal with transactions itself out of the box. So the only option to get rid of a service layer was to use e.g. &lt;code&gt;@Transactional&lt;/code&gt; at a Spring MVC controller e.g. which is rather a sub-optimal solution.&lt;/p&gt;
&lt;p&gt;So actually we were quite reluctant to the idea of applying transactions to Hades DAO instances as there were some crucial points to consider:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Actually a DAO layer might not be at the right level of abstraction.&lt;/strong&gt; Usually you define transactions on a more business related method than a plain &lt;code&gt;save(…)&lt;/code&gt; or &lt;code&gt;findByUsername(…)&lt;/code&gt;. So if we enable transactions at DAO methods we have to make sure that they seamlessly can be expanded to more coarse grained methods and the DAOs take part in those transactions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;If we apply transactions we don&amp;#8217;t want to imply our transaction model to the user&amp;#8217;s application.&lt;/strong&gt; As Spring provides various means to define transactions, we don&amp;#8217;t want to take that decision from the developer. So in case she wants to decide for a particular model, she has to be able to do so, no matter what we chose.&lt;/li&gt;
&lt;li&gt;Although the transactional behavior that we define for CRUD methods might be okay for 90% of the use cases &lt;strong&gt;there has to be a way to override the defaults and replace them by some custom one.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;As Spring 3.0 &lt;strong&gt;support&lt;/strong&gt;s&lt;strong&gt; multiple transaction managers&lt;/strong&gt; via &lt;code&gt;@Transactional&lt;/code&gt; we have to make sure we participate in the right transaction depending on in which context the DAO is used.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It has to be easy to define transaction configuration for DAO interfaces&lt;/strong&gt; containing the finder methods.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We decided to use &lt;code&gt;@Transactional&lt;/code&gt; annotations at the &lt;code&gt;GenericJpaDao&lt;/code&gt; implementation class and activate annotation based transactions for the proxies explicitly through the &lt;code&gt;GenericDaoFactoryBean&lt;/code&gt;. This means that the CRUD operations of the DAO instances will be transactional if called standalone or participate in a transaction in case there&amp;#8217;s already one running for the current transaction manager (read up details on multiple transaction managers &lt;a title="Spring reference documentation on multiple="&gt;here&lt;/a&gt;). So it doesn&amp;#8217;t matter if you declare your transactional boundaries via &lt;code&gt;@Transactional&lt;/code&gt;, too, or use e.g. XML configuration or even &lt;code&gt;TransactionTemplate&lt;/code&gt;. This gets us solutions for issues 1 and 2.&lt;/p&gt;
&lt;p&gt;Issue 5 is quite easy to solve as you can simply annotate the finder methods of your DAO interface (or the interface itself) with &lt;code&gt;@Transactional&lt;/code&gt; and transactions get applied as you are used to with Spring.&lt;/p&gt;
&lt;p&gt;The actual tricky part is issue 3. The main idea here is to simply redeclare the CRUD method originally declared in &lt;code&gt;GenericDao&lt;/code&gt; inside your concrete DAO interface and reconfigure transactions as you like. So supposed you want to get rid of the readOnly flag at &lt;code&gt;readByPrimaryKey(…)&lt;/code&gt; set to true (as we chose to default the transaction configuration to, as this applies some performance optimizations on the persistence provider as well as the JDBC driver), you can do this as follows:&lt;/p&gt;
&lt;pre class="java" name="code"&gt;public interface UserDao extends GenericDao&amp;lt;User, Long&amp;gt; {

  @Override
  @Transactional
  User readByPrimaryKey(Long key);
}&lt;/pre&gt;
&lt;p&gt;Getting this to work needs some reflection magic as we of course still have to delegate the call to that method to the &lt;code&gt;GenericJpaDao&lt;/code&gt; instance but according to the Java Reflection API it of course does only implement &lt;code&gt;GenericDao.readByPrimaryKey(…)&lt;/code&gt; and not &lt;code&gt;UserDao.readByPrimaryKey(…)&lt;/code&gt;. Long story short, we can find out the method that has to be invoked so we can hand this reconfiguration model to the user and gain much flexibility on this side.&lt;/p&gt;
&lt;p&gt;Issue 4 is not that interesting as we simply have to configure our internal &lt;code&gt;TransactionInterceptor&lt;/code&gt; to lookup the appropriate &lt;code&gt;PlatformTransactionManager&lt;/code&gt; instance in a lazy-loading-like fashion but that all happens under the covers and you don&amp;#8217;t need to take care of this.&lt;/p&gt;
&lt;p&gt;So let me quickly summarize what 2.0.0.RC2 brings you in regard of transactions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Transactional CRUD methods (everything declared in &lt;code&gt;GenericDao&lt;/code&gt;) with appropriate defaults (&lt;code&gt;readOnly&lt;/code&gt; flag set to true on read-only methods) that automatically take part in more coarse grained transactions if necessary&lt;/li&gt;
&lt;li&gt;The ability to use &lt;code&gt;@Transactional&lt;/code&gt; for your concrete DAO interfaces&lt;/li&gt;
&lt;li&gt;The ability to reconfigure the transactional behavior of the CRUD methods by simply redeclaring a method inside the concrete DAO interface&lt;/li&gt;
&lt;/ul&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/pQgDdWkjM7I" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2010/06/hades-2-0-0-rc2-introduces-transactional-daos/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2010/06/hades-2-0-0-rc2-introduces-transactional-daos/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2010/06/hades-2-0-0-rc2-introduces-transactional-daos/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[Changing a project&#8217;s artifact id in Sonar]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/qKvZKDQdxck/" />
		<id>http://www.olivergierke.de/wordpress/?p=490</id>
		<updated>2010-06-02T15:57:07Z</updated>
		<published>2010-06-02T15:56:48Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="IT" /><category scheme="http://www.olivergierke.de/wordpress" term="howto" /><category scheme="http://www.olivergierke.de/wordpress" term="opensource" /><category scheme="http://www.olivergierke.de/wordpress" term="tools" /><category scheme="http://www.olivergierke.de/wordpress" term="workaround" />		<summary type="html"><![CDATA[Sonar is a great tool to take care of code quality in your software projects. I use it heavily to monitor the open source projects I am involved with. When working on getting Hades published into Maven central I had to polish it&#8217;s pom.xml and felt the need to align the parent project&#8217;s artifact to [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2010/06/changing-a-projects-artifact-id-in-sonar/">&lt;p&gt;&lt;a title="Sonar" href="http://sonar.codehaus.org/" target="_blank"&gt;Sonar&lt;/a&gt; is a great tool to take care of code quality in your software projects. I use it heavily to monitor the &lt;a title="Sonar instance @ synyx.org" href="http://techqa.synyx.org" target="_blank"&gt;open source projects I am involved with&lt;/a&gt;. When working on getting &lt;a title="Hades project home" href="http://hades.synyx.org" target="_blank"&gt;Hades&lt;/a&gt; published into Maven central I had to polish it&amp;#8217;s &lt;code&gt;pom.xml&lt;/code&gt; and felt the need to align the parent project&amp;#8217;s artifact to our chosen OSGi compatible package notation for artifacts. So prior to releasing it to Maven central I changed the artifact id from &lt;code&gt;hades-parent&lt;/code&gt; to &lt;code&gt;org.synyx.hades.parent&lt;/code&gt;. Everything fine until I pushed the metrics of the 1.5.1 release into Sonar.&lt;/p&gt;
&lt;p&gt;Sonar created a new project, as it cannot know about my refactoring. So what to do? I spoke to &lt;a title="Simon Brandhof @ Twitter" href="http://twitter.com/SimonBrandhof" target="_blank"&gt;Simon Brandhof&lt;/a&gt; and apparently there&amp;#8217;s no feature in Sonar to change the artifact id via the user interface. So I opened a JIRA &lt;a title="JIRA issue for renaming projects" href="http://jira.codehaus.org/browse/SONAR-1608" target="_blank"&gt;issue&lt;/a&gt; for it, feel free to vote for it if you like. Meanwhile we could achieve this by manually altering the &lt;code&gt;kee&lt;/code&gt; column inside the &lt;code&gt;PROJECTS&lt;/code&gt; table. It contains entries of the form &lt;code&gt;${groupId}:${artifactId}(:${branchName})&lt;/code&gt; for entries of type &lt;code&gt;PRJ&lt;/code&gt; (i guess that stands for project. Altering these entries solved the problem.&lt;/p&gt;
&lt;p&gt;Thanks to Simon and Verschdl for help!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/qKvZKDQdxck" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2010/06/changing-a-projects-artifact-id-in-sonar/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2010/06/changing-a-projects-artifact-id-in-sonar/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2010/06/changing-a-projects-artifact-id-in-sonar/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[Upgrade you Roo addons to 1.1.0]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/KfHzg7XGZO0/" />
		<id>http://www.olivergierke.de/wordpress/?p=476</id>
		<updated>2010-06-02T15:58:21Z</updated>
		<published>2010-06-01T07:52:30Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="IT" /><category scheme="http://www.olivergierke.de/wordpress" term="howto" /><category scheme="http://www.olivergierke.de/wordpress" term="roo" /><category scheme="http://www.olivergierke.de/wordpress" term="spring" />		<summary type="html"><![CDATA[Spring Roo 1.1.0 will be based on OSGi and Apache Felix in particular as runtime platform. This of course will affect the already existing addons developed for Roo. The core ones are of course updated by the Spring Roo team but in case you have developed a custom one the steps needed to be taken [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2010/06/upgrade-you-roo-addons-to-1-1-0/">&lt;p&gt;Spring Roo 1.1.0 will be based on OSGi and Apache Felix in particular as runtime platform. This of course will affect the already existing addons developed for Roo. The core ones are of course updated by the Spring Roo team but in case you have developed a custom one the steps needed to be taken are not really obvious. However, I took some time studying the core addons and here&amp;#8217;s a step by step guide that takes you from a 1.0.x addon to a 1.1.0 one:&lt;span id="more-476"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Make sure, your project version is a valid OSGi vesion&lt;/strong&gt;Default Maven version scheme is invalid for &lt;code&gt;SNAPSHOT&lt;/code&gt; versions as the 3rd part of the version has to be purely numeric in OSGi. In case you ignore this, you won&amp;#8217;t get the bundle deployed into the Roo OSGi runtime. So you have to stick to something like &lt;code&gt;0.1.0.BUILD-SNAPSHOT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Change packaging of your project to bundle&lt;/strong&gt;As your plugin will result in an OSGi bundle you need to change the packaging from simple &lt;code&gt;jar&lt;/code&gt; to &lt;code&gt;bundle&lt;/code&gt;. This will cause the Maven bundle plugin creating the necessary metadata for you out of the box.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Change the type of the dependencies to bundle&lt;/strong&gt;Similar to the point above you need to reference dependencies as bundles. Again, to let the Maven bundle plugin do its job.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sync build section of your pom with the one provided in the addon template&lt;/strong&gt;We had to do some changes to them &lt;code&gt;pom.xml&lt;/code&gt; created for artifacts so you will need to catch up with them. This is mostly related to the Maven bundle plugin as well as the Maven SCR plugin (see next point for details).
&lt;pre class="bash"&gt;project --topLevelPackage com.mycompany.myproject.roo.addon \
  --template ROO_ADDON_SIMPLE&lt;/pre&gt;
&lt;p&gt;The easiest way to do so is simply creating a dummy addon project using the template and copy the plugin configuration into your pom.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Replace @ScopeDevelopment annotations with @Component and @Service&lt;/strong&gt;Roo uses Apache Felix as OSGi runtime and thus uses &lt;code&gt;@Component&lt;/code&gt; and &lt;code&gt;@Service&lt;/code&gt; annotations in combination with the Maven SCR plugin (for details see &lt;a title="Maven SCR plugin" href="http://felix.apache.org/site/apache-felix-maven-scr-plugin.html"&gt;Maven SCR plugin documentation&lt;/a&gt;) to create descriptors for the OSGi declarative services infrastructure.
&lt;pre class="java"&gt;@Service
@Component
public class MyCommands implements CommandMarker {

  @Reference MyOperations operations;

  // Your code goes here
}&lt;/pre&gt;
&lt;p&gt;So every &lt;code&gt;@ScopeDevelopment&lt;/code&gt; annotation you used at your command and operations classes has to be replaced by &lt;code&gt;@Service&lt;/code&gt; and &lt;code&gt;@Component&lt;/code&gt;. If you had injected other services into your command or operations class you can use &lt;code&gt;@Reference&lt;/code&gt; to wire that into your component instance. Note, that your class will have to implement at least one interface Felix can publish the component instance under. As there might be further tweaks necessary, have a closer look at the output the Maven SCR plugin generates. It will log errors in case you still need to change something.&lt;/li&gt;
&lt;/ol&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/KfHzg7XGZO0" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2010/06/upgrade-you-roo-addons-to-1-1-0/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2010/06/upgrade-you-roo-addons-to-1-1-0/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2010/06/upgrade-you-roo-addons-to-1-1-0/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>Oliver Gierke</name>
						<uri>http://www.olivergierke.de</uri>
					</author>
		<title type="html"><![CDATA[The unknown 2nd Spring triangle]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/olivergierke/soulpower/~3/ISz493B0izU/" />
		<id>http://www.olivergierke.de/wordpress/?p=469</id>
		<updated>2010-05-09T16:45:54Z</updated>
		<published>2010-05-09T16:45:54Z</published>
		<category scheme="http://www.olivergierke.de/wordpress" term="IT" /><category scheme="http://www.olivergierke.de/wordpress" term="aop" /><category scheme="http://www.olivergierke.de/wordpress" term="coding" /><category scheme="http://www.olivergierke.de/wordpress" term="java" /><category scheme="http://www.olivergierke.de/wordpress" term="migration" /><category scheme="http://www.olivergierke.de/wordpress" term="patterns" /><category scheme="http://www.olivergierke.de/wordpress" term="spring" />		<summary type="html"><![CDATA[When skimming through Spring presentations explaining the building blocks of the framework you&#8217;ll often find a so called Spring triangle consisting of the following 3 parts: Dependency Injection Aspect Oriented Programming Portable Service Abstraction These 3 principles surround a plain POJO programming model and enable Spring to achieve what it is famous for. Portable and [...]]]></summary>
		<content type="html" xml:base="http://www.olivergierke.de/wordpress/2010/05/the-unknown-2nd-spring-triangle/">&lt;p&gt;When skimming through Spring presentations explaining the building blocks of the framework you&amp;#8217;ll often find a so called Spring triangle consisting of the following 3 parts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Dependency Injection&lt;/li&gt;
&lt;li&gt;Aspect Oriented Programming&lt;/li&gt;
&lt;li&gt;Portable Service Abstraction&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These 3 principles surround a plain POJO programming model and enable Spring to achieve what it is famous for. Portable and maintainable Java software. Having that said, there is another triangle in my opinion that is touches developers even more when working with Spring. This triangle captures the way Spring can be &lt;em&gt;configured&lt;/em&gt;, thus &lt;em&gt;used&lt;/em&gt; and &amp;#8211; to a larger extend &amp;#8211; introduced into a project. But first things first, here&amp;#8217;s what I am talking about.&lt;span id="more-469"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;XML configuration&lt;/li&gt;
&lt;li&gt;Annotation configuration&lt;/li&gt;
&lt;li&gt;Programmatic usage&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Especially choosing between the first two approaches to configuration are an often discussed topic. To be honest, I don&amp;#8217;t think a Spring project will fail because of this issue. There a few guidelines one can use to decide on that topic but I don&amp;#8217;t want to go into that in detail in this post. Let&amp;#8217;s take a look at the three styles of usage from a more general perspective and how they enable usage of Spring itself.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;XML configuration&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This way of using Spring is probably a well known way to users that have worked with Spring for a long period of time already. Admittedly, this approach has several downsides (e.g. verbosity of configuration) but also results in some kind of application blueprint you can gain information about how a module is structured at a quick glance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Annotation configuration&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This style of configuration is gaining more and more of traction these days. Spring&amp;#8217;s support for annotations is set up broadly since 2.5. 3.0 extends that support furthermore by supporting standardized annotations for dependency injection like &lt;code&gt;@Inject&lt;/code&gt;. Besides that Spring comes up with an annotation configuration style called JavaConfig, where you write dedicated configuration classes and annotate &lt;em&gt;them&lt;/em&gt; to define configuration metadata. This solves the problem of configuration of 3rd party classes that you cannot annotate directly anymore (e.g. DataSources etc.) that plain annotation config does not offer a solution for.&lt;/p&gt;
&lt;p&gt;Both styles of configuration (XML and annotations) leverage the usage of Spring as framework, defining application and infrastructure components that are managed by Spring at runtime. Besides that there is a 3rd option that is often neglected but a helpful one in certain scenarios.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Programmatic usage of Spring&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As all Spring abstractions (transactions, persistence etc.) are programmatically usable, which means you can simply drop the appropriate JAR into your classpath and use the classes as is using Spring &lt;em&gt;as library&lt;/em&gt; instead of as framework then. As they are written to support dependency injection the usage of the huge simplyfication of JDBC e.g. can be used by instantiating JdbcTemplate, handing it a DataSource and off you go.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Why do I mention that&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First thing is, that contrary to popular believe using Spring does not mean huge XML config files or even starting with the introduction of Dependency Injection into your application. You can use declarative transactions by simply using the AOP and transaction API &lt;em&gt;programatically&lt;/em&gt; in your already existing factory classes e.g. You can simplify your existing JDBC code hugely by using &lt;code&gt;JdbcTemplate&lt;/code&gt; without bothering with AOP or Dependency Injection at all. Thus there are many possible ways to adopt Spring with your application, it is no &amp;#8220;one size has to fit all&amp;#8221; approach but rather &lt;em&gt;enables you as developer&lt;/em&gt; to make a decision that suits your problem at hand.&lt;/p&gt;
&lt;p&gt;There is no silver bullet, more power to the developer!&lt;/p&gt;
&lt;p&gt;Second, the 2nd triangle is the actual means to allow exactly what I just described above. It enables developers to use each part of the first triangle and makes Spring the Swiss knife of application frameworks. So why choosing an axe instead? ;)&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/olivergierke/soulpower/~4/ISz493B0izU" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.olivergierke.de/wordpress/2010/05/the-unknown-2nd-spring-triangle/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.olivergierke.de/wordpress/2010/05/the-unknown-2nd-spring-triangle/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://www.olivergierke.de/wordpress/2010/05/the-unknown-2nd-spring-triangle/</feedburner:origLink></entry>
	</feed>

