I am trying to use a join to avoid an extra select when I retrieve an object that has a property which is another object (not a primitive or native type).
The relevant fragments of my XML file are: <resultMap id="YMap" class="Y"> <result property="ID" column="Y_ID"/> <result property="Name" column="Y_Name"/> <result property="Description" column="Y_Desc"/> </resultMap> <resultMap id="XMap" class="X"> <result property="ID" column="X_ID"/> <result property="Name" column="X_Name"/> <result property="Description" column="X_Desc"/> <result property="MyY" resultMapping="MyStatements.YMap"/> </resultMap> ... <select id="X.Get" resultMap="XMap"> select * from X, Y where X.X_ID = #value# and X.Y_ID = Y.Y_ID </select> This works fine as long as X.Y_ID is non null. However, the database schema allows X.Y_ID to be null. From an application perspective, I'd like to reconstitute an instance of class X where it's MyY property (of type Y) will be null when X.Y_ID is null. So the above does not work. The only alternatives I can currently think of are: 1) replace <result property="MyY" resultMapping="MyStatements.YMap"/> with <result property="MyY" select="Get.Y"/> and change X.Get to remove the join... but that means every X.Get will invoke a Y.Get and any X.GetAll (assuming I create one) will invoke multiple Y.Get (N+1) selects problem. or 2) Use caching. This is fine and I intend to at some point, but would like to get everything working first before going the caching route. Any ideas?