Thursday, December 16, 2010

Populate Immutable Objects with iBatis Mapping

In a previous post, I provided iBatis configuration and mapping that supported populating Java objects on a per-property basis, i.e. the classes in use had to provide setters for this approach. Here I describe another iBatis pattern that populates immutable objects with more than a few properties.First, I assume the target object uses the Builder Pattern to support construction, since this is a useful approach for immutable classes exposing, as mentioned, "more than a few properties".

Continuing from my original example, the iBatis mapping might look something like this (I omit the one-to-many issue from my original post since that's not crucial to this discussion):

I'll omit the boilerplate around consuming the iBatis configuration and obtaining an iBatis session factory. Let's just go with the "miracle occurs here" approach, and cut to the Java-side chase - this first provides an interface with full classname matching the iBatis mapper namespace and a method with name matching the iBatis select statement id:

No comments:

Post a Comment

Welcome to the Perimeter Sweep Blog

My blog is largely intended to be a placeholder for topics involving software development - architecture, technology drill-downs, best practices, various solutions, workarounds, gotchas and the like - things that will remind me what I've learned over time. If it helps you out also - all the better.

Subscribe To This Blog

About Me

I'm a Senior Software Engineer, an avid runner, and formerly a professional musician...currently the proud father of a super-tyke, raising two Siberian Huskies and married to my best friend. Life is good.