I have a shipping information object that matches the table it is stored in in MySQL with the exception that the "Address" is an object (in the object) however it is an AddressId in the DB Table. My current result map looks like this:
<resultMap type="ShippingInfo" id="shippingInfoResult">
<result column="orderItemId" property="orderItemId" />
<result column="shipingDate" property="shippingDate" javaType="java.sql.Date" />
<result column="numberShipped" property="numberShipped" />
<result column="carrier" property="carrier" />
<result column="tracking" property="tracking" />
<result column="shippingType" property="shippingType" />
<association property="address" column="addressId" javaType="com.Foo.Bar.address.Address" select="com.Foo.Bar.address.AddressMapper.read" />
</resultMap>
I have been trying to figure out how to get MyBatis to select the address based on the addressId that is returned in the query but have as of yet been unsuccessful. It is currently setting the value of address to null rather than an empty Address object which I would expect it to do.
Is it possible to do this or do I need to format my query differently to include more data? Do I need to do something else different so that it will at least set the address field to an empty address rather than null?
Thank you for any assistance.
UPDATE I want to clarify, if there is an address that matches the addressId it pulls said address without issue and populates it. The issue I am running into is when the id is set to 0 and the query returns zero results. It appears to be setting the address to an empty address object for one instance and the rest are all set to null.