<?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/"
	>

<channel>
	<title>Soul Power &#187; Hades</title>
	<atom:link href="http://www.olivergierke.de/wordpress/category/it/hades-it/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.olivergierke.de/wordpress</link>
	<description>www.olivergierke.de</description>
	<lastBuildDate>Thu, 15 Jul 2010 23:03:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>DDD Specifications with Hades</title>
		<link>http://www.olivergierke.de/wordpress/2010/07/ddd-specifications-with-hades/</link>
		<comments>http://www.olivergierke.de/wordpress/2010/07/ddd-specifications-with-hades/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 23:03:46 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[domain driven design]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[opensource]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=513</guid>
		<description><![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 [...]]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago, I attended <a href="http://www.java-forum-stuttgart.de" target="_blank" title="Java Forum Stuttgart">Java Forum Stuttgart</a>, a really nice one-day conference to hear interesting talks, meet fellow developers and colleagues. The first talk I attended was held by <a href="http://adrianhummel.wordpress.com/" target="_blank" title="Adrian Hummel's blog">Adrian Hummel</a> and Mischa Kölliker entitled <a href="http://www.java-forum-stuttgart.de/abstracts.html#D1" target="_blank" title="Rich domain model with JPA 2.0">Rich domain model with JPA 2.0</a>. 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.<span id="more-513"></span></p>
<p>One part of their talk was dealing with the specifications concept of the <a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?ie=UTF8&#038;s=books-intl-de&#038;qid=1279234366&#038;sr=8-1" target="_blank" title="Domain Driven Design @ Amazon">Domain Driven Design</a> book by Eric Evans. <code>Specification</code>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 <code>boolean</code>, so it can be regarded as predicate over the entity. The example Adrian gave in his talk (and also in a <a href="http://adrianhummel.wordpress.com/2010/07/02/composed-specifications-using-jpa-2-0/" target="_blank" title="Adrian Hummel on Specifications">blogpost</a> he dropped a few days later) is a soccer player, who can be characterized as &#8220;fair player&#8221; or as &#8220;bonus eligible&#8221;.</p>
<p>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):</p>
<pre name="code" class="java">CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery&lt;Player&gt; q = cb.createQuery(Player.class);
Root&lt;Player&gt; player = q.from(Player.class);

q.where(/** Build your where clause here **/);

return em.createQuery(q).getResultList();</pre>
<p>As you see there&#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 <code>q.where(…)</code> method. What Adrian and Mischa now proposed is introducing a <code>Specification&lt;T&gt;</code> interface that simply provides a callback method that gets the <code>CriteriaBuilder</code>, <code>CriteriaQuery&lt;T&gt;</code> and <code>Root&lt;T&gt;</code> and reduces that to a JPA Predicate which can be handed to the <code>q.where(…)</code> method then (code originally coined by Adrian):</p>
<pre name="code" class="java">public interface Specification&lt;T&gt; {

 Predicate toPredicate(CriteriaBuilder cb,
   CriteryQuery&lt;T&gt; q, Root&lt;T&gt; root);
}</pre>
<p><strong>Specifications in Hades</strong></p>
<p>To make this available in Hades we simpy add a method <code>readAll(Specification&lt;T&gt; spec)</code> to <code>GenericDao</code> interface and <code>GenericJpaDao</code> implementation and implement it as follows:</p>
<pre name="code" class="java">public List&lt;T&gt; readAll(Specification&lt;T&gt; spec) {
  CriteriaBuilder cb = em.getCriteriaBuilder();
  CriteriaQuery&lt;T&gt; q = cb.createQuery(getDomainClass());
  Root&lt;T&gt; player = q.from(getDomainClass());

  q.where(spec.toPredicate(cb, q, root);

  return em.createQuery(q).getResultList();
}</pre>
<p>So what this gains you is a possibility to simply add new <code>Specification</code> implementations and thus &#8220;extend&#8221; the DAO without the need to add finders e.g.</p>
<p><strong>One more thing</strong></p>
<p>The really cool part about the <code>Specification</code>s is, that &#8211; as you can concatenate JPA <code>Predicate</code>s with <code>and</code> and <code>or</code> &#8211; you can do this with some minor effort on the <code>Specification</code>s, too. I added a small class that provides some syntactical sugar to make something like this possible:</p>
<pre name="code" class="java">playerDao.readBySpecification(
  where(isFair()).and(isEligibleForBonus()));</pre>
<p>This probably needs some explaination. First, <code>isFair()</code> and <code>isEligibleForBonus()</code> are static methods on a (for example) <code>PlayerSpecifications</code> class that return a <code>Specification</code> instance creating the JPA <code>Predicate</code> instance. The <code>where(…)</code> method is also a static one on a helper class that pretty much returns itself, implements <code>Specification</code> in turn and and provides the concatenation methods to chain <code>Specification</code>s and build new <code>Specification</code>s on the fly. Thus you can easily implement atomic predicates for the entity and build more complex expression from it &#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.</p>
<p>A big thank you to Adrian and Mischa for a huge part of this new feature =).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2010/07/ddd-specifications-with-hades/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hades &#8211; standing on the shoulders of giants</title>
		<link>http://www.olivergierke.de/wordpress/2010/06/hades-standing-on-the-shoulders-of-giants/</link>
		<comments>http://www.olivergierke.de/wordpress/2010/06/hades-standing-on-the-shoulders-of-giants/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 19:40:18 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[aop]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=500</guid>
		<description><![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 [...]]]></description>
			<content:encoded><![CDATA[<p>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:</p>
<ol>
<li>It only works if you call <code>MyDao.save(…)</code> explicitly</li>
<li>It only works for the root entity you persist, not transitive ones.</li>
</ol>
<p>These drawbacks have caused Will Jaynes to open up a <a href="http://redmine.synyx.org/issues/53" title="Enable more than just root entity auditing"  target="_blank">ticket</a> 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&#8217;s the story…<span id="more-500"></span></p>
<p><strong>The right tool for the job</strong></p>
<p>Actually, implementing auditing with AOP was not the right choice in the first place. Well, it&#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.</p>
<p><strong>Entity listeners</strong></p>
<p>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 <code>@PrePersist</code> or <code>@PreUpdate</code> 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 <code>@EntityListeners</code> or configure them in your <code>orm.xml</code>. The reason they never seemed suitable for me is that they get instantiated by the JPA provider and thus &#8211; by default &#8211; lack any means of injecting dependencies into them (the <code>AuditorAware</code> instance knowing who is the current user in our case).</p>
<p><strong>@Configurable</strong></p>
<p>Fortunately Spring offers injecting dependencies into classes created with <code>new</code> by adding an <code>@Configurable</code> 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 <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">former blogpost</a> or the <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-atconfigurable">reference documentation</a>.)</p>
<p>So let&#8217;s recap what we have here: I let the aspect be compiled into my <code>AuditingEntityListener</code> and activate  as well as a prototype bean of the listener getting a <code>StubAuditorAware</code> injected in my integration tests config file. Hm, doesn&#8217;t work… What&#8217;s wrong? Here&#8217;s the critical part of the reference doc.</p>
<blockquote><p>Instances of <code>@Configurable</code> 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 <code>depends-on</code> bean attribute to manually specify that the bean depends on the configuration aspect.</p></blockquote>
<p>Okay, it seems the aspect is not yet active when my <code>LocalContainerEntityManagerFactoryBean</code> 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 <code>depends-on</code> attribute to the bean that manually instantiates objects (the <code>EntityManagerFactoryBean</code> in our case). First: what bean to depend on since spring-configured has no id. Ah, it turns out Spring registers the aspect under <code>org.springframework.context.config.internalBeanConfigurerAspect</code>. So I&#8217;d essentially need something like this to make sure the <code>EntityManagerFactory</code> already sees the DI aspect:</p>
<pre name="code" class="xml">

<context:spring-configured />

<bean class="….LocalContainerEntitiyManagerFacotryBean"
  depends-on="org.springframework.context.config.internalBeanConfigurerAspect"/>
</pre>
<p>Well, wait… of course I could document that this was necessary but that would bloat Hades user&#8217;s infrastructure configuration, expose Spring internal bean names and make things unnecessary complex.</p>
<p><strong>Spring container hooks &#8211; BeanFactoryPostProcessor</strong></p>
<p>Okay, so what we essentially need to do is transparently add a <code>depends-on="org.springframework.context.config.internalBeanConfigurerAspect"</code> to the chosen <code>EntityManagerFactoryBean</code> bean definition. Fortunately we can do this programatically by using one of the Spring container hooks, the <code>BeanFactoryPostProcessor</code>. So I simply implemented a <code>AuditingBeanFactoryPostProcessor</code> that transparently adds the (additional) <code>depends-on</code> to bean definitions that create an <code>EntityManagerFactory</code>. So the benefit here is that we can leave other user defined beans untouched. Let&#8217;s take a look on what we have to configure on the Spring side to get things up and running:</p>
<pre name="code" class="xml">
<context:spring-configured />
<bean class="….AuditingBeanFactoryPostProcessor" />

<bean class="….auditing.support.AuditingEntityListener">
<property value="auditorAware" ref="auditorAware" />
</bean>

<bean id="auditorAware" class="com.acme.MyAuditorAwareImpl" />
</pre>
<p>As you can see, there&#8217;s a lot of boilerplate XML config here. The only thing really custom is the delaration of the <code>MyAuditorAwareImpl</code>. Now guess what? There&#8217;s some Spring for that…  </p>
<p><strong>Spring namespaces</strong></p>
<p>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 <code>dao-config</code> element in the Hades namespace so why not add one to activate auditing? So here&#8217;s what we end up with:</p>
<pre name="code" class="xml"><hades:auditing auditor-aware-ref="auditorAware" />

<bean id="auditorAware"
  class="com.acme.MyAuditorAwareImpl" /></pre>
<p>Quite neat, isn&#8217;t it? So let&#8217;s summarize what we have gained from the plain auditing feature view:</p>
<ol>
<li>We get transparent auditing on all JPA managed entities, whether they are the root entity or a transitive one.</li>
<li>No need to call <code>MyDao.save(…)</code> to trigger auditing.</li>
</ol>
<p>Nice, feature completed ;). Now let&#8217;s take another step back an reflect what brought us there:</p>
<ol>
<li>Spring&#8217;s ability to inject dependencies into objects instantiated with <code>new</code> through <code>@Configurable</code> and AOP.</li>
<li>Prevented custom configuration spread around into other beans thorugh Spring&#8217;s <code>BeanFactoryPostProcessor</code> container hook.</li>
<li>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.</li>
</ol>
<p>Enough praising here, enjoy auditing with Hades! =)</p>
<p>P.S.: In case you want to take a glance at the sources checkout the <a href="http://redmine.synyx.org/projects/hades/repository/revisions/11827">commits</a> I&#8217;ve done for the <a href="http://redmine.synyx.org/issues/53" title="Enable more than just root entity auditing">feature request</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2010/06/hades-standing-on-the-shoulders-of-giants/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hades 2.0.0.RC2 introduces transactional DAOs</title>
		<link>http://www.olivergierke.de/wordpress/2010/06/hades-2-0-0-rc2-introduces-transactional-daos/</link>
		<comments>http://www.olivergierke.de/wordpress/2010/06/hades-2-0-0-rc2-introduces-transactional-daos/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 19:11:24 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[releases]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=495</guid>
		<description><![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 days, [...]]]></description>
			<content:encoded><![CDATA[<p>Our latest Hades <a title="Hades release announcement" href="http://redmine.synyx.org/news/18" target="_blank">release</a> 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.<span id="more-495"></span></p>
<p>These days, some kind of back-to-the-basics approach regarding architecture layering is widely accepted as best practices. Thus you don&#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&#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. <code>@Transactional</code> at a Spring MVC controller e.g. which is rather a sub-optimal solution.</p>
<p>So actually we were quite reluctant to the idea of applying transactions to Hades DAO instances as there were some crucial points to consider:</p>
<ol>
<li><strong>Actually a DAO layer might not be at the right level of abstraction.</strong> Usually you define transactions on a more business related method than a plain <code>save(…)</code> or <code>findByUsername(…)</code>. 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.</li>
<li><strong>If we apply transactions we don&#8217;t want to imply our transaction model to the user&#8217;s application.</strong> As Spring provides various means to define transactions, we don&#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.</li>
<li>Although the transactional behavior that we define for CRUD methods might be okay for 90% of the use cases <strong>there has to be a way to override the defaults and replace them by some custom one.</strong></li>
<li>As Spring 3.0 <strong>support</strong>s<strong> multiple transaction managers</strong> via <code>@Transactional</code> we have to make sure we participate in the right transaction depending on in which context the DAO is used.</li>
<li><strong>It has to be easy to define transaction configuration for DAO interfaces</strong> containing the finder methods.</li>
</ol>
<p>We decided to use <code>@Transactional</code> annotations at the <code>GenericJpaDao</code> implementation class and activate annotation based transactions for the proxies explicitly through the <code>GenericDaoFactoryBean</code>. This means that the CRUD operations of the DAO instances will be transactional if called standalone or participate in a transaction in case there&#8217;s already one running for the current transaction manager (read up details on multiple transaction managers <a title="Spring reference documentation on multiple=">here</a>). So it doesn&#8217;t matter if you declare your transactional boundaries via <code>@Transactional</code>, too, or use e.g. XML configuration or even <code>TransactionTemplate</code>. This gets us solutions for issues 1 and 2.</p>
<p>Issue 5 is quite easy to solve as you can simply annotate the finder methods of your DAO interface (or the interface itself) with <code>@Transactional</code> and transactions get applied as you are used to with Spring.</p>
<p>The actual tricky part is issue 3. The main idea here is to simply redeclare the CRUD method originally declared in <code>GenericDao</code> inside your concrete DAO interface and reconfigure transactions as you like. So supposed you want to get rid of the readOnly flag at <code>readByPrimaryKey(…)</code> 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:</p>
<pre class="java" name="code">public interface UserDao extends GenericDao&lt;User, Long&gt; {

  @Override
  @Transactional
  User readByPrimaryKey(Long key);
}</pre>
<p>Getting this to work needs some reflection magic as we of course still have to delegate the call to that method to the <code>GenericJpaDao</code> instance but according to the Java Reflection API it of course does only implement <code>GenericDao.readByPrimaryKey(…)</code> and not <code>UserDao.readByPrimaryKey(…)</code>. 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.</p>
<p>Issue 4 is not that interesting as we simply have to configure our internal <code>TransactionInterceptor</code> to lookup the appropriate <code>PlatformTransactionManager</code> instance in a lazy-loading-like fashion but that all happens under the covers and you don&#8217;t need to take care of this.</p>
<p>So let me quickly summarize what 2.0.0.RC2 brings you in regard of transactions:</p>
<ul>
<li>Transactional CRUD methods (everything declared in <code>GenericDao</code>) with appropriate defaults (<code>readOnly</code> flag set to true on read-only methods) that automatically take part in more coarse grained transactions if necessary</li>
<li>The ability to use <code>@Transactional</code> for your concrete DAO interfaces</li>
<li>The ability to reconfigure the transactional behavior of the CRUD methods by simply redeclaring a method inside the concrete DAO interface</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2010/06/hades-2-0-0-rc2-introduces-transactional-daos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hades 1.5 released</title>
		<link>http://www.olivergierke.de/wordpress/2010/04/hades-1-5-released/</link>
		<comments>http://www.olivergierke.de/wordpress/2010/04/hades-1-5-released/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 09:23:15 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[releases]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=459</guid>
		<description><![CDATA[As you probably already might have noticed, yesterday we released Hades 1.5. Alongside with that the firs 2.0 release candiate sees the light of the day, too. Let me just take some lines to elaborate on the specialty of this release.
Why 1.5?
The first question that might arise is why this release is 1.5 whereas it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>As you probably already might have noticed, yesterday we released Hades 1.5. Alongside with that the firs 2.0 release candiate sees the light of the day, too. Let me just take some lines to elaborate on the specialty of this release.</p>
<p><strong>Why 1.5?</strong></p>
<p>The first question that might arise is why this release is 1.5 whereas it&#8217;s predecessor was 1.1.2. Originally the release was planned as 1.2 but as it introduces some long-ranging features and changes we thought it might be worth indicating that in a larger step of version numbers. As 2.0 is already taken for our JPA 2 upgrade, 1.5 was the choice to go. So what do I mean with &#8220;long-ranging&#8221;?<span id="more-459"></span></p>
<p>Since it&#8217;s beginning Hades relied on two major interfaces: <code>GenericDao</code> and <code>Persistable</code> where as especially the latter raised some discussions <a title="Why do we need to implement Persistable?" href="http://redmine.synyx.org/boards/2/topics/8" target="_self">here</a> and there. Although it is not that of a big deal to implement a 3rd party interface with an entity class it was indeed a hurdle for adoption. So why was it introduced in the first place. <code>GenericDao</code> had the aim to abstract between creation and updates of objects. Although there slight semantic differences this maps to the difference between using <code>EntityManager</code> methods <code>persist(…)</code> and<code> merge(…)</code>. To know what to call when <code>save(…)</code> is being called on <code>GenericDao</code> we have to be able to differentiate between a new and an existing entity. As this algorithm might vary from entity to entity, we chose to leave the burdon to decide that to the entity developer by implementing the interface.</p>
<p>Although implementing this interface should not be a big deal actually, we (and the developer community) were not really satisfied with that solutions as the technical infrastructure slightly leaks into the domain abstraction which is somewhat suboptimal kindly speaking. The good news is: as of Hades 1.5 there is no need to implement <code>Persistable</code> anymore. The DAO implementation now uses a reflective approach to lookup the id property of the entity and inspects its value. If it is <code>null</code>, the entity is regarded as new or as already existing otherwise. So that&#8217;s the default. If you need to tweak the semantics of new, simply implement <code>Persistable</code> as the algorithm will be simply calling <code>isNew()</code> on you instance then. So in effect, the interface comes into play if explicitly needed and not in any other case.</p>
<p>That&#8217;s the big news. Behind that we have a few new features regarding the XML namespace to be used in Spring applications. In case you have multiple <code>EntityManagerFactory</code> beans declared (e.g. in case you work with more than one JPA persistence unit), you can now point the <code>dao-config</code> and <code>dao</code> elements to a specific EMF bean by using <code>entity-manager-factory-ref</code> attribute. Furthermore using <code>exclude-filter</code> and <code>include-filter</code> (probably known from Spring&#8217;s context namespace) can be used to tune DAO auto configuration in a more fine grained way. Besides that we have done a general overhaul to the query creation subsystem and now also allow keywords like <code>Between</code>, <code>LessThan</code> and <code>GreaterThan</code> in method names. To round things up we&#8217;ve fixed a few minor bugs here and there. For more details read the <a title="Changelog" href="http://redmine.synyx.org/versions/show/34" target="_blank">changelog</a> or the updated <a title="Reference documentation" href="http://redmine.synyx.org/attachments/download/96" target="_blank">reference documentation</a>.</p>
<p><strong>Hades 2.0</strong></p>
<p>Alongside this important step we make another one. JPA 2.0 specification was released a while ago and most existing JPA 1 application wil definately benefit from an upgrade as the new spec version really fills gaps the old one left to workaround for the developers. So what is our approach to the new spec. From a Hades point of view the most intresting part of the new spec is the criteria API as user&#8217;s probably will base their custom DAO implementations on it. Furthermore upgrading (Spring) applications demands applications to upgrade to Spring 3.0 and a new major version of the persistence provider of choice we choose to dedicate a 2.0 version of Hades to it.</p>
<p>So the first release candidate builds on top of Spring 3.0.2 as well as Hibernate 3.5, EclipseLink 2.0 as well as OpenJPA 2.0 Beta 3. We will probably wait for our final release until OpenJPA is final, too, but as the majority of users are split between Hibernate and EclipseLink we think that rolling out a release candidate is a good way to get feedback and battle proof the new version. The major change inside Hades 2.0 is that we dropped support of the read-by-example way to access entities. This had to be implemented in a provider specific way so that we could even simplify the codebase in that regard. Furthermore the DAO abstraction is now clearly centered around <code>GenericDao</code> and not blurred with additional interfaces.</p>
<p>So if you can upgrade to Spring 3.0.x and the JPA 2 ready persistence provider already, give Hades 2.0 a try. It should be a drop in replacement in this case. Having that said, it&#8217;s probably worth mentioning that even Hades 1.5 can be used with JPA 2.0 but requires more extensive pom configuration on the developer side (as Spring 2.5.6 does not support JPA 2). As you&#8217;d end up with a dependency setup similar to the one decalred in 2.0 you&#8217;re probably better of just upgrading to Hades 2.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2010/04/hades-1-5-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Devoxx talk on Hades available at Parleys.com</title>
		<link>http://www.olivergierke.de/wordpress/2010/02/my-devoxx-talk-on-hades-available-at-parleys-com/</link>
		<comments>http://www.olivergierke.de/wordpress/2010/02/my-devoxx-talk-on-hades-available-at-parleys-com/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 10:56:25 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[devoxx]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[parleys]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=431</guid>
		<description><![CDATA[As I was just remembered on Twitter, my talk on Hades at Devoxx 2009 is now freely available to watch at Parleys.com. So watch it here or direcly at Parleys.

]]></description>
			<content:encoded><![CDATA[<p>As I was just remembered on <a href="http://twitter.com/olivergierke/status/8803404629" target="_blank">Twitter</a>, my talk on <a title="Blogposts regarding Hades" href="http://www.olivergierke.de/wordpress/tag/hades" target="_blank">Hades</a> at <a href="http://www.devoxx.com" target="_self">Devoxx</a> 2009 is now freely available to watch at <a title="Parleys website" href="http://devoxx.parleys.com" target="_blank">Parleys.com</a>. So watch it here or direcly at <a title="Hades @ Devoxx 2009 - Parleys.com" href="http://parleys.com/d/1470" target="_blank">Parleys</a>.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="440" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="pageId" value="1470" /><param name="src" value="http://www.parleys.com/share/parleysshare2.swf?pageId=1470" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="440" height="350" src="http://www.parleys.com/share/parleysshare2.swf?pageId=1470" pageid="1470" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2010/02/my-devoxx-talk-on-hades-available-at-parleys-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hades 1.0 released</title>
		<link>http://www.olivergierke.de/wordpress/2009/10/hades-1-0-released/</link>
		<comments>http://www.olivergierke.de/wordpress/2009/10/hades-1-0-released/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 11:20:32 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[releases]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=374</guid>
		<description><![CDATA[Let me announce that as of yesterday Hades ships in its first stable version 1.0. As this of course marks an important milestone let me just briefly give an overview of the features Hades provides. I will start with the very basic features in this post and continue to elaborate on advanced ones in furthers [...]]]></description>
			<content:encoded><![CDATA[<p>Let me announce that as of yesterday Hades ships in its first stable version 1.0. As this of course marks an important milestone let me just briefly give an overview of the features Hades provides. I will start with the very basic features in this post and continue to elaborate on advanced ones in furthers blog posts.</p>
<p><strong>Context</strong></p>
<p>Hades is a library that supports Java developers when implementing persistence layers on top of JPA. Under the covers Hades uses Spring to achieve a lot of it&#8217;s functionality. Although there is tight integration with Spring (see bullet points below) that will give Spring users an enhanced development experience there&#8217;s no need to have you application based on Spring.</p>
<p><strong>JPA &amp; DAO pattern</strong></p>
<p>JPA eases object persistence a lot. Caveats of version 1.0 are broadly addressed in upcoming 2.0 release. Nevertheless the API could need some bells&#8217;n'whistles to align real world development purposes. So the very core of Hades consists of a generic DAO wrapper implementation of JPAs <code>EntityManager</code> that pretty much straightens its API.</p>
<p><strong>Basics &#8211; generic DAO instances</strong></p>
<p>Creating instances of this wrapper can be done easily. Suppose you have a JPA entity <code>User</code> with an id type of <code>Long</code>:</p>
<pre name="code" class="java">EntityManager em = ... // obtain entity manager
GenericDao userDao = GenericJpaDao.create(em,
  User.class);</pre>
<p>This gains you basic crud functionality for this entity as well as typed collection access (<code>EntityManager</code> is lacking that) plus sorting and pagination support (e.g. via <code>readAll(Pagable pageable);</code>).</p>
<p><strong>Finder methods</strong></p>
<p>Very seldomly applications stop at only requiring CRUD access to entities. A huge amount of persistence operations resides in executing query methods. With Hades you simply provide an interface extending <code>GenericDao</code> and declare the methods you want to execute queries for:</p>
<pre name="code" class="java">public interface UserDao extends
  GenericDao&lt;User, Long&gt; {

  User findByUsername(String username);

  List&lt;User&gt; findByLastname(String lastname);
}</pre>
<p>To obtain an instance of that DAO you can use <code>GenericDaoFactory</code> as follows:</p>
<pre name="code" class="java">EntityManager em = ... // obtain EntityManager
GenericDaoFactory factory =
  GenericDaoFactory.create(em);
UserDao userDao = factory.getDao(UserDao.class);</pre>
<p><strong>From the method to the query</strong></p>
<p>Of course you&#8217;ll immediately ask: &#8220;Okay, what queries will be executed for these methods?&#8221;. Actually there are 3 ways to define them:</p>
<ol>
<li>Not defining them :) &#8211; Hades will the derive the query from the method name on instance creation and validate the querie. Thus,<code> findByUsername(String username)</code> would result in <code>select u from User u where u.username = ?</code></li>
<li>Use JPA named queries &#8211; if you align to the naming convention of <code>${entityName}.${methodName}</code> Hades will use the declared query to be executed. In the case of <code>findByUsername(String username)</code> your query would have to be named <code>User.findByUsername</code></li>
<li>Use <code>@Query</code> annotation &#8211; in case you rather don&#8217;t want to separate query from DAO interface you can use Hades&#8217; <code>@Query</code> annotation to declare the query directly at the method, e.g. <code>@Query("from User u where u.lastname = ?")</code></li>
</ol>
<p>By default these 3 ways are hierarchical, thus an <code>@Query</code> will trump a named query. If none of them can be found Hades will derive the query from the method name. If you need more detailed control over the resolution behaviour you can configure this on the factory.</p>
<p><strong>Spring</strong></p>
<p>Hades uses Spring itself under the hood and thus it seems resonable to provide seamless integration into the framework for users in turn. On a very low level view Hades provides a <code>GenericDaoFactoryBean</code> that pretty much allows the same setup as the code samples showed above. Besides that, the more powerful approach is using the Spring namespace:</p>
<pre name="code" class="xml">&lt;hades:dao-config basePackage="com.acme.**.dao" /&gt;</pre>
<p>This will cause Hades scanning all <code>dao</code> packages below <code>com.acme</code> for extensions of <code>GenericDao</code> and create the appropriate beans.</p>
<p><strong>Conclusion</strong></p>
<p>The features shown are only the core one&#8217;s of what Hades can do for you. The will be follow up posts on query methods in detail, integrating custom data access code, auditing support. If you don&#8217;t want to wait for that feel free to skim through the reference documents at <a title="Hades project site" href="http://hades.synyx.org" target="_blank">http://hades.synyx.org</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2009/10/hades-1-0-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Conference autumn</title>
		<link>http://www.olivergierke.de/wordpress/2009/08/conference-autumn/</link>
		<comments>http://www.olivergierke.de/wordpress/2009/08/conference-autumn/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 17:27:03 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[devoxx]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[synyx]]></category>
		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=341</guid>
		<description><![CDATA[After I got started holding presentations at conferences at Devoxx last year, this autumn will get really packed with presentation dates. I will kick of the season at GearConf in Düsseldorf. On Thursday Oct. 1st I will speak about increasing developer productivity with Mylyn. During development of Hades Mylyn became an indispensable tool to get [...]]]></description>
			<content:encoded><![CDATA[<p>After I got started holding presentations at conferences at Devoxx last year, this autumn will get really packed with presentation dates. I will kick of the season at <a href="http://www.gearconf.com/" target="_blank">GearConf</a> in Düsseldorf. On Thursday Oct. 1st I will speak about increasing developer productivity with <a href="http://www.eclipse.org/mylyn/" target="_blank">Mylyn</a>. During development of <a href="http://hades.synyx.org" target="_blank">Hades</a> Mylyn became an indispensable tool to get work done, to keep a controlling eye on relations between commits, changesets and what got done why. I will continue at GearConf on Friday Oct. 2nd intoducing <a href="http://sonar.codehaus.org/" target="_blank">Sonar</a>, a tool to control and monitor code quality. It&#8217;s yet another tool that is really handy developing Hades and all other projects I am involved in and keep their code&#8217;s quality on a continued high level.</p>
<p>After that I will kick of Hades autumn tour on October 27th at this year&#8217;s <a href="http://javasymposium.techtarget.com/" target="_blank">The Server Side Java Symposium</a> in Prague, Czech Republic, which I already mentioned here. The tour will be interrupted by the <a href="http://www-05.ibm.com/de/events/rsc/" target="_blank">IBM Rational Software Conference 2009</a> in Düsseldorf where I will present <a href="http://www.skywayperspectives.org/portal/web/guest/home" target="_blank">Skyway Builder</a>, a tool to create Spring based web applications in a model driven way. A key focus of this talk will (as the name of the conference suggests) the integration into IBM Rational, esp. UML to Code and vice versa features. We at <a href="http://www.synyx.de" target="_blank">Synyx</a> are consulting partner of <a href="http://www.skywaysoftware.com" target="_blank">Skyway Software</a> to care for european customers and users of the community edition of Skyway Builder.</p>
<p>The conference autumn will be closed with a talk at a conference I already really enjoyed last year: <a href="http://www.devoxx.com" target="_blank">Devoxx 2009</a>. I was invited to hold a 45 minute <a href="http://www.devoxx.com/display/DV09/Easing+JPA+data+access+with+Hades" target="_blank">session</a> during the &#8220;Tools in Action&#8221; track at the University day. I really look forward to all of these talks. If you ocassionally attend one of the events, feel free to say hello and discuss thoughts. See you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2009/08/conference-autumn/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hades News &#8211; Conferences 2009 / Article</title>
		<link>http://www.olivergierke.de/wordpress/2009/08/hades-news-conferences-2009-article/</link>
		<comments>http://www.olivergierke.de/wordpress/2009/08/hades-news-conferences-2009-article/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 11:30:51 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[devoxx]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[releases]]></category>
		<category><![CDATA[talks]]></category>
		<category><![CDATA[tssjs09]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=321</guid>
		<description><![CDATA[
I just want to announce that I am going to speak about Hades at Devoxx and The Server Side Java Symposium this year. The TSSJS takes place in Prague (Czech Republic) from Oct. 27th to 28th whereas Devoxx will be held between Nov. 16th and  20th in Antwerp (Beligum). I am thrilled by the list [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-317" title="TSSJS 2009 Logo" src="http://www.olivergierke.de/wordpress/wp-content/uploads/2009/08/TSSJS09-speaking-125x125.gif" alt="TSSJS 2009 Logo" width="125" height="125" /><img class="alignleft size-full wp-image-320" title="Devoxx 2009" src="http://www.olivergierke.de/wordpress/wp-content/uploads/2009/08/logo1.jpg" alt="Devoxx 2009" width="300" height="112" /></p>
<p style="clear: both; padding-top: 20px">I just want to announce that I am going to speak about <a href="http://hades.synyx.org" target="_blank">Hades</a> at <a href="http://www.devoxx.com" target="_blank">Devoxx</a> and <a href="http://javasymposium.techtarget.com/" target="_blank">The Server Side Java Symposium</a> this year. The TSSJS takes place in Prague (Czech Republic) from Oct. 27th to 28th whereas Devoxx will be held between Nov. 16th and  20th in Antwerp (Beligum). I am thrilled by the list of speakers I can share the opportunity to speak with and really look forward to the events. Feel free to say hello and communicate opinions and ideas personally.</p>
<p>In addition to the small promo tour we do in autumn we have released version 0.6 of Hades that mainly frees finder methods from name prefixes entirely. Check the <a title="Hades 0.6 release announcement" href="http://redmine.synyx.org/news/show/8" target="_blank">announcement</a> or the <a title="Hades 0.6 reference documentation" href="http://redmine.synyx.org/attachments/45/hades-reference.pdf" target="_blank">reference documentation</a> for details. In the beginning of September there will be a last feature release that will expand the functionality of executing finder queries into executing manipulating queries, too. If you like to check out a stable preview of this version, check it out in our <a title="Hades @ Synyx Maven repository" href="http://repo.synyx.org/org/synyx/hades/org.synyx.hades" target="_blank">Maven repositories</a>.</p>
<p>German speaking readers might be interested in the article I wrote for JavaMagazin a while ago. You can find a PDF version of that article <a title="Generische DAOs mit Hades - Oliver Gierke - JavaMagazin 7/09" href="http://www.olivergierke.de/wordpress/wp-content/uploads/2009/08/JM-7.09_Gierke_Hades.pdf" target="_blank">here</a>. It <span style="text-decoration: line-through;">should also be</span> is also published as online version on the JAXenter website <a href="http://it-republik.de/jaxenter/artikel/Projekt-Hades-2499.html" target="_blank">here</a> <span style="text-decoration: line-through;">in a few days</span>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2009/08/hades-news-conferences-2009-article/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Article on Hades in current issue of German JavaMagazin</title>
		<link>http://www.olivergierke.de/wordpress/2009/06/article-on-hades-in-current-issue-of-german-javamagazin/</link>
		<comments>http://www.olivergierke.de/wordpress/2009/06/article-on-hades-in-current-issue-of-german-javamagazin/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 05:03:20 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java user group]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[synyx]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=304</guid>
		<description><![CDATA[The June issue of the German JavaMagzin features an article about Hades written by myself. I sketch out issues implementing persistence layers briefly and introduce solutions to these issues using Hades. Furthermore fellow developer Alexander Hanschke introduced Java User Group Mannheim in yet another article, too. Check out the current issue and get your copy.
Beyond [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_312" class="wp-caption alignleft" style="width: 115px"><img class="size-full wp-image-312" title="jm-709" src="http://www.olivergierke.de/wordpress/wp-content/uploads/2009/06/jm-709.jpg" alt="JavaMagazin 7/09" width="105" height="150" /><p class="wp-caption-text">JavaMagazin 7/09</p></div>
<p>The June issue of the German <a title="JavaMagazin - June 2009" href="http://it-republik.de/jaxenter/java-magazin-ausgaben/EJB-3.0-000304.html" target="_blank">JavaMagzin</a> features an article about <a href="http://www.synyx.org/de/projects/hades.html" target="_blank">Hades</a> written by myself. I sketch out issues implementing persistence layers briefly and introduce solutions to these issues using Hades. Furthermore fellow developer <a title="Alexander Hanschke's blog" href="http://blog.alexander-hanschke.de/" target="_blank">Alexander Hanschke </a>introduced <a title="Homepage of the Java User Group Mannheim" href="http://www.majug.de" target="_blank">Java User Group Mannheim</a> in yet another article, too. Check out the current issue and get your copy.</p>
<p>Beyond that, we at Synyx decided to give the part of our homepage that deals with our OpenSource projects a brush up. Check out <a title="Synyx OpenSource homepage" href="http://www.synyx.org" target="_blank">http://www.synyx.org</a> to start diggin into the <a title="Synyx.org - Projects" href="http://www.synyx.org/de/projects/" target="_blank">projects</a>, read up our <a title="Synyx.org - Blogs" href="http://www.synyx.org/de/blogs/" target="_blank">developer&#8217;s blogs</a> and keep in touch via the <a title="Synyx.org - Redmine" href="http://redmine.synyx.org" target="_blank">project tracker</a>. Kudos to <a title="Philip Reiman's blog" href="http://bifrost.rei-network.info/blog/" target="_blank">Philip Reiman</a> who did most of the work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2009/06/article-on-hades-in-current-issue-of-german-javamagazin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Diggin&#8217; into Spring 3 transactional test facilities</title>
		<link>http://www.olivergierke.de/wordpress/2009/05/diggin-into-spring-3-transactional-test-facilities/</link>
		<comments>http://www.olivergierke.de/wordpress/2009/05/diggin-into-spring-3-transactional-test-facilities/#comments</comments>
		<pubDate>Thu, 28 May 2009 18:16:06 +0000</pubDate>
		<dc:creator>Oliver Gierke</dc:creator>
				<category><![CDATA[Hades]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[hades]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[transactions]]></category>

		<guid isPermaLink="false">http://www.olivergierke.de/wordpress/?p=299</guid>
		<description><![CDATA[Today I devoted my day to a general check in how far Hades can be run with the latest Spring 3 milestone. After managing the typical Maven foo I had a project profile up and running that builds Hades against Spring 3 M3 and executes the tests against it. In case you try to migrate [...]]]></description>
			<content:encoded><![CDATA[<p>Today I devoted my day to a general check in how far Hades can be run with the<a title="Download Spring 3 M3" href="http://www.springsource.com/download/community?project=" target="_blank"> latest Spring 3 milestone</a>. After managing the typical Maven foo I had a project profile up and running that builds <a title="Hades project site" href="http://hades.synyx.org" target="_blank">Hades</a> against Spring 3 M3 and executes the tests against it. In case you try to migrate some of your code, too, and wonder where <code>spring-agent</code> JAR has gone: its <code>org.springframework.instrument</code> now. But back to topic.</p>
<p>The build went fine but unfortunately some of my test cases broke when executed under M3. I noticed that things started to get fuzzy with the first test case that was supposed to throw an exception. I have some test cases that look as follows:</p>
<pre name="code" class="java">@Test(expected=DataAccessException.class)
public void checkDoesNotCascadeIfNotConfigured() {

	// Setup some persistent object graph that is
	// supposed to throw an exception

	userDao.saveAndFlush(user);
}</pre>
<p>The key thing to notice here is that I flush the database as the constraint violation I want to expose is only checked at the time the data gets pushed to the database actually. Stepping through the code of Spring testing library in a first level of detail, I realized that the exception is thrown correctly and even detected as the one that is supposed to be thrown. Nevertheless the test method was marked as failed with the exception supposed to be thrown. Furthermore all upcoming tests failed with a duplicate key exception as setting up the test fixture failed right in the beginning. What the heck was going on?</p>
<p>It seemed obvious to me that there would have to be something wrong with the transaction management, so I digged a little further in that direction. Finally I found out this one: in <a title="Commit 655 - Spring SVN" href="https://fisheye.springsource.org/browse/spring-framework/trunk/org.springframework.test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java?r1=134&amp;r2=655" target="_blank">this commit</a> Jürgen Höller added a <code>transactionStatus.flush()</code> during the rollback of a transaction after test execution. This of course raises the exception I wanted to raise a second time but &#8211; unfortunately &#8211; after the moment the first exception had already been checked to be the expected one. Thus the second exception bubbles up causing the test and the rollback to fail.</p>
<p>As I spoke to <a title="Jürgen Höller's Blog" href="http://blog.springsource.com/author/juergenh/" target="_blank">Jürgen</a> we found out that the flush was implemented due to a <a title="JIRA Ticket adressing the issue" href="http://jira.springframework.org/browse/SPR-5315" target="_blank">improvement</a> filed in JIRA. Fortunately there is already <a title="Another JIRA Ticket adressing the issue" href="http://jira.springframework.org/browse/SPR-5699" target="_blank">another ticket</a> that adresses the issue. Waiting for RC1 to see this fixed&#8230;</p>
<p>Hades itself seems to be Spring 3 ready already, so if you play around with both of &#8216;em, I&#8217;d be happy to address any issues you face.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.olivergierke.de/wordpress/2009/05/diggin-into-spring-3-transactional-test-facilities/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
