I use primarily immutable model objects for all of my stored data. As a result all of my member variables are final which means I have to use the constructor args to set them. Currently constructor args do not support the columnPrefix option from associations. As a result I have to build many result maps that are essentially duplicates with different column values since other workarounds are too slow. It would be really nice if the columnPrefix could be added to the constructor arg implementation.
Comment From: harawata
Could you provide a test case or example app ? There is a test case that uses constructor mapping with columnPrefix. It is possible that there is some corner case to which columnPrefix is not correctly applied, but we need a repro to proceed.
Thank you, Iwao
Comment From: christopherpicard
Sure, I will translate the case I am using into a test case and post it when I am complete.
Comment From: Davio
Currently, columnPrefix is only specified for associations. I couldn't find a usage within constructor in the examples.
What I'd like to do is something like the following:
<constructor>
<idArg name="id" column="id"/>
<arg name="complexProperty" columnPrefix="prop_" autoMapping="true"/>
</constructor>
Where complexProperty itself has sub-properties, such as 'key' and 'value' where the columns would be named 'prop_key' and 'prop_value' respectively.
Comment From: christopherpicard
As long as resultMaps are supported in that approach it would work for me. My example is like this:
<constructor>
<idArg name="id" column="id"/>
<arg columnPrefix="Minimum" resultMap = "distanceResultMap" javaType="Distance"/>
<arg columnPrefix="Maximum" resultMap = "distanceResultMap" javaType="Distance"/>
...
</constructor>
<resultMap id="distanceResultMap" type="Distance">
<constructor>
<arg column="Distance" javaType="_double"/>
<arg column="DistanceUnits" javaType="String"/>
<constructor>
</resultMap>
The columns in this case would be MinimumDistance, MinimumDistanceUnits, MaximumDistance, and MaximumDistanceUnits.
Currently i have to write two different Result maps for the minimum and maximum value.
Comment From: harawata
Thank you for the examples, @Davio @christopherpicard ! I will look into it.
Comment From: harawata
Hi @christopherpicard , @Davio
Sorry for a late response, but it will be available in version 3.5.0. It would be great if you could try the latest SNAPSHOT and see if it works as you expected.