Analytics

Monday, May 10, 2010

JBoss Seam White Paper Published

JBoss Seam has been in use within industry for a few years now and has a substantial following in the developer market.  Recently, I published a paper highlighting how Seam enables Rapid Application Development (RAD) in the context of Agile environments.  The paper was written in collaboration with my colleague, Jacob Orshalick. 

JBoss Seam: Agile RIA Development Framework

Much of Seam's features are widely documented in forums and on the JBoss site. However, this white paper does not just highlight the many features of Seam.  The paper takes real world use case scenarios and demonstrates how Seam's features can be applied to increase speed of product delivery.  The use cases are geared toward solving business problems and user needs, while the gory details of a technical solution are avoided so that Seam's utility is understood by a wider audience. 

The audience of the paper includes product champions, sponsors, managers, business analysts, architects and developers.  In essence, the goal of the paper is to demonstrate how Seam can be applied to real world scenarios and allow a development team to focus on business needs rather than extraneous concerns, resulting in faster product delivery.

Sunday, April 4, 2010

My Comprehensive Reading List

Recently I decided to track all the books I have read since I graduated college and compile them into one comprehensive list.  What I discovered was that I have read many technical books and that my interests lie in a few discrete other areas.  All the books I have read contribute to my career path and my personal life in some way, and I try to apply anything I learned from reading.  I am interested to see what has influenced you as a developer as well as a person.

I welcome any recommendations, suggestions, thoughts, or criticisms related to these readings.  I am particularly interested in the category I labeled as "Social Science", as I think the themes in those books correlate with the software workplace in many ways, but with a different perspective.  On the same note, I am always looking for the inspiring novel or story to sharpen up the emotional side of my brain.

Technical
  • The Pragmatic Programmer: From Journeyman to Master, by Andrew Hunt and David Thomas
  • Ship It!: A Practical Guide to Successful Software Projects, by Jared Richardson, Will Gwaltney, Jr
  • Domain Driven Design: Tackling Complexity in the Heart of Software, by Eric Evans 
  • Clean Code: A Handbook of Agile Software Craftsmanship, by Robert C. Martin
  • Design Patterns: Elements of Reusable Object-Oriented Software (Hardcover), by Erich Gamma, Richard Helm, Ralph Johnson, John M. Vlissides
  • Head First Design Patterns, by Eric T Freeman, Elisabeth Robson, Bert Bates, Kathy Sierra
  • Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process, by Craig Larman
  • Agile and Iterative Development: A Manager's Guide, by Craig Larman
  • Refactoring: Improving the Design of Existing Code, by Martin Fowler, Kent Beck, John Brant, and William Opdyke
  • Seam Framework: Experience the Evolution of Java EE, by Michael Juntao Yuan, Jacob Orshalick, Thomas Heute
  • Maven: A Developer's Notebook, by Vincent Massol and Timothy M. O'Brien
  • JBoss RichFaces 3.3, by Demetrio Filocamo
  • Getting Started with Grails, by Jason Rudolph
  • Grails in Action, by Glen Smith and Peter Ledbrook
  •  Driving Technical Change, by Terrance Ryan
  • The Agile Samurai, by Jonathan Rasmusson
  • Getting Real, by 37Signals
  • Programming in Groovy, by Venkat Subramaniam
  • Building and Testing with Gradle, by Tim Berglund and Matthew McCullough  
  • Practices of an Agile Developer, by Venkat Subramaniam and Andy Hunt
  • Manage It, by Johanna Rothman 
  • Joel on Software, by Joel Spolsky
  • Theory of Relativity, an intuitive explanation, by Jeffrey Bennet   
Social Sciences
  • Naked Economics: Undressing the Dismal Science, by Charles Wheelan
  • The Tipping Point: How Little Things Can Make a Big Difference, by Malcolm Gladwell
  • Outliers: The Story of Success, by Malcolm Gladwell
  • Blink, by Malcolm Gladwell
  • Kluge: The Haphazard Evolution of the Human Mind, by Gary Marcus 
  • First Things First, by Stephen R. Covey, A. Roger Merrill, Rebecca R. Merrill 
  • The 7 Habits of Highly Effective People, by Stephen R. Covey
  • Freakonomics: A Rogue Economist Explores the Hidden Side of Everything, by Steven D. Levitt, Stephen J. Dubner
  • The World is Flat: a Brief History of the Twenty-First Century, by Thomas L. Friedman
  • Ethics for Everyone, by Arthur Dobrin
  • The Happiness Hypothesis: Finding Modern Truth in Ancient Wisdom, by Jonathan Haidt 
  • Shalom in the Home: Smart Advice for a Peaceful Life, by Rabbi Shmuley Boteach  
  • The Principle of the Path: Smart Advice for a Peaceful Life, by Andy Stanley
  •  Under the Banner of Heaven, by John Krakauer
  • The Big Short, by Michael Lewis
  • God the failed Hypothesis, by Victor Stenger
  • God is not Great, by Christopher Hitchens 
  • Discover your Inner Economist, by Tyler Cowen 
  • Liar's Poker, by Michael Lewis 
  • The End of Faith, by Sam Harris 
  • Moneyball, by Michael Lewis  
  • Freedom At Midnight, by Larry Collins and Dominique Lapierre  
  •  Power of Habit, by Charles Duhigg
  • It Starts With Food, Dallas and Melissa Hartwig 
  • Free Lunch, David Johnston 
  • Predictable Irrational, Dan Arielly 
  • Bonobo and the Atheist, Frans De Waal 
     Biographies
    • Three Cups of Tea: One Man's Mission to Promote Peace . . . One School at a Time, by Greg Mortenson and David Oliver Relin
    • The Boy Who Harnessed the Wind: Creating Currents of Electricity and Hope, by William Kamkwamba and Bryan Mealer
    • Gandhi An Autobiography: The Story of My Experiments With Truth, by Mohandas Karamchand (Mahatma) Gandhi
    • The Autobiography of Martin Luther King, Jr., by Martin Luther King Jr. and Clayborne Carson
    • Baseball's Great Experiment: Jackie Robinson and His Legacy, by Jules Tygiel
    • Faith of My Fathers: A Family Memoir, by John McCain and Mark Salter
    • Hang Time: Days And Dreams With Michael Jordan, by Bob Greene
    • Playing for Keeps: Michael Jordan and the World He Made, by David Halberstam 
    • It's Not About the Bike: My Journey Back to Life, by Lance Armstrong 
    • Crazy Horse and Custer, by Stephen Ambrose
    • The Color of Water, by James McBride
    • Lessons From a Third Grade Dropout, by Rick Rigsby
    • The 5 Love Languages, by Gary Chapman
    • Unbroken, by Lauren Hildenbrand
    Novels
    • A Thousand Splendid Suns, by Khaled Hosseini
    • And the Mountains Echoed, by Khaled Hosseini
    • For One More Day, by Mitch Albom 
    • The Five People You Meet in Heaven, by Mitch Albom 
    • Siddhartha, by Hermann Hesse
    • The Da Vinci Code, by Dan Brown
    • Tuesdays with Morrie: An Old Man, a Young Man, and Life's Greatest Lesson, by Mitch Albom
    • The Twentieth Wife, by Indu Sundaresan 
    • On the Road, by Jack Kerouac
    • Fever Pitch, by Nick Hornby
    • The Alchemist, by Paolo Coehlo 
    • The Girl Who Played With Fire, by Stieg Larsson 
    • The Girl Who Kicked the Hornet's Nest, by Stieg Larsson
    • The Help, by Kathryn Stockett
    • The Hunger Games, by Suzanne Collins
    • Catching Fire, by Suzanne Collins  
    • Mockingjay, by Suzanne Collins
    • The Lucky One, by Nicholas Sparks
    •  True North, by Jim Harrison
    Parenting
    • How to Really Love Your Child, by D. Ross Campbell 
    • Raising Happiness: 10 Simple Steps for More Joyful Kids and Happier Parents, by Christine Carter
    • 1-2-3 Magic: Effective Discipline for Children 2-12, by Thomas W. Phelan
    • Toddler 411: Clear Answers & Smart Advice for Your Toddler, by Denise Fields and Ari Brown
    • Fatherhood, by Bill Cosby and Alvin F. Poussaint
    • Bavy 411, by Dr. Ari Brown

    Sunday, March 28, 2010

    One to One Shared Primary Key is Eagerly Fetched in Hibernate

    One to One Shared Primary Key is Eagerly Fetched
     
    Every so often Hibernates presents some peculiarity that, at first observance, doesn't make much sense.  However, once you investigate the peculiarity thoroughly, you see why hibernate behaves the way it does. 
     
    An instance occurs when mapping a one-to-one relationship with a shared primary key.  In certain instances, even if this mapping is declared to fetch lazily, hibernate will eagerly fetch the association.  The reason is because due to the nature of a shared primary key, hibernate does not know whether to initialize the association to null or not without actually joining against the associated table. 
     
    Explore through an Example
     
    Let's set up an example to further explain the situation.  Let's say we want to map a one-to-one association with a shared primary key for two basic entities: a Passenger and a AirlineTicket.  A Passenger can only have one Airline ticket, and an Airline ticket can only have one passenger.  For our example, the relationship will be bidirectional from Passenger to AirlineTicket.
     




    We can map the objects with JPA and hibernate with the code snippets below. Note that we have marked the association from Passenger to AirlineTicket as LAZY.
    
    ....
    @Entity
    @Table(name = "PASSENGER")
    public class Passenger {
    
        @Id
        @GeneratedValue
        @Column(name = "PASSENGER_ID")
        private Long id;
    
        @Column(name = "NAME")
        private String name;
        
        @Column(name = "BIRTHDATE")
        private int age;
        
        @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "passenger")
        private AirlineTicket airlineTicket;
    ... 
    }  
    

    
    ...
    @Entity
    @Table(name = "AIRLINE_TICKET")
    @org.hibernate.annotations.GenericGenerator(name="passenger-primarykey", strategy="foreign",
     parameters={@org.hibernate.annotations.Parameter(name="property", value="passenger")
    })
    public class AirlineTicket {
    
        @Id
        @GeneratedValue(generator = "passenger-primarykey")
        @Column(name = "PASSENGER_ID")
        private Long id;
        
        @Column(name = "SEAT_NUMBER")
        private int seatNumber;
        
        @Column(name = "CLASS")
        private String clazz;
        
        @OneToOne
        @PrimaryKeyJoinColumn
        private Passenger passenger;
        
        public AirlineTicket() {
        }
    ...
    }  
    

    However, when we load the entity with a entityManager.find(..), hibernate issues a join in the generated sql to eagerly load the AirlineTicket!  If the Passenger entity was loaded with a ejql statement such as "from Passenger", hibernate will issue two separate sql statements back to back: one to load the passenger, and then another to load the airline ticket (which essentially is an eager fetch.)
     
    Why does this peculiarity occur?  When hibernate loads the Passenger object, it has to initialize its attributes.  AirlineTicket is an association which is mapped with a shared primary key.  Therefore, in order to find out whether the AirlineTicket is null or not, hibernate must issue a join to the AIRLINE_TICKET table to check if a row exists with the same primary key as the Passenger object.  If hibernate abstained from issuing a join to AIRLINE_TICKET and proceeded to instantiate a proxy for AirlineTicket, the Passnger object would contain a AirlineTicket, even if there was no real association in the database.
     
    Solution
     
    In order to take advantage of lazy loading when you have a shared primary key one-to-one relationship, you can use the optional=false setting on the relationship. For example, the AirlineTicket reference in the Passenger object would have optional=false.  This conveys to hibernate that the there will always be an AirlineTicket for a Passenger, thus it can create a proxy and it is guarenteed to have a corresponding object.
     
    Design Considerations
     
    So what are the situations to use a shared primary key in a one-to-one?  This begs the question of when is it best to use a one-to-one relationship?  One-to-One relationships are modeled in the domain when one object instance has an exclusive relationship with another object instance.  Simple examples would be [Person, Heart], [Husband, Wife], [HeadCoach, NflTeam]. (Of course, you could make silly arguments to debunk this, but you get the drift). 
     
    The easiest mapping for one-to-one relationship is to have a foreign kep from the owning entity to the other object.  In our Passenger example, the PASSENGER table would have a foreign key column AIRLINE_ID. This approach has no peculiarities with lazy loading, as hibernate can figure out if the association exists without joining to another table. All it has to do is check the foreign key for null. 
     
    A shared primary key for one-to-one mapping is appropriate only if the association is non-optional.  Meaning each end of the association has to exist.  If one side exists, so does the other.  If you map without this symbiotic relationship, you will run into the peculiarities above and possibly have to eager fetch for no reason.  This could lead to performance issues.  Shared primary keys save a column on the database, but the mapping is a little more complicated and peculiarities exist.  Hardware is cheap, knowledge is expensive.  Consider this approach carefully.

    Source Code 
    one-to-one.zip
     
    References: