|
Hi, Actually I only need a solution for select;
the other types are handled in the DAO. Let’s assume the following
classes exist. Class A { id propertyA_1 propertyA_2 type } Class B extends A { propertyB_1 propertyB_2 propertyB_3 } The following resultmaps are defined: <resultMap id=”resultMap_A”
class=”A”> <result property=”id”
column=”id”/> <result property=”propertyA_1”
column=”propertyA_1”/> <result property=”propertyA_2”
column=”propertyA_2”/> <discriminator column=”type”
javaType="int"> <subMap value="1"
resultMap="resultMap_B"/> </discriminator> </resultMap> <resultMap id=”resultMap_B”
class=”B” extends=”resultMap_A”> <result property=”propertyB_1”
column=”propertyB_1”/> <result property=”propertyB_2”
column=”propertyB_2”/> <result property=”propertyB_3”
column=”propertyB_3”/> </resultMap> What I would like to have is a way to do
two things: * writing a statement that joins A and B
directly (when I know the type in advance) * writing a statement that queries only A
(when I do not know the type) The first one is not a problem and works
perfectly well, with and without a discriminator defined. The second one is
where my problem is, I want to execute a statement that specifies class A as a
result, iBATIS encounters the discriminator and checks which properties are
required, when not all properties are available in the resultset, it should
execute a second statement which fetches the additional properties required by
the subclass (B in the example). This statement could be specified as attribute
in the subMap-tag. Below is what I think the resulting sqlMap
looks like: <resultMap id=”resultMap_A”
class=”A”> <result property=”id”
column=”id”/> <result property=”propertyA_1”
column=”propertyA_1”> <result property=”propertyA_2”
column=”propertyA_2”> <discriminator column=”type”
javaType="int"> <subMap value="1"
resultMap="resultMap_B" select=”B_get”/> </discriminator> </resultMap> <resultMap id=”resultMap_B”
class=”B” extends=”resultMap_A”> <result property=”propertyB_1”
column=”propertyB_1”> <result property=”propertyB_2”
column=”propertyB_2”> <result property=”propertyB_3”
column=”propertyB_3”> </resultMap> <select id="A_get"
parameterClass="int" resultClass="A"> SELECT type FROM A WHERE id = #value# </select> <select id="B_get"
parameterClass="int" resultClass="B"> SELECT * FROM A, B WHERE A.id = B.id AND A.id = #value# </select> When I execute B_get, all values are
already available, so no additional statement is required, the query produces class
B. When I execute A_get, only the type is
available, iBATIS detects which resultMap is required using the discriminator,
and checks whether all columns are available, this is not the case, so B_get
gets executed, now all columns are available, the query produces class B, when
not all columns are available, iBATIS first checks for a nested discriminator,
otherwise throws an error. I hope you understand from this lengthy
post what I would like to see added to iBATIS. I know iBATIS is not an
O/R-mapper, so I don’t expect behaviour ala JDO at all, but would really
like to see a solution for ISA, as this is a common scenario, especially in our
application. Let me know your thoughts, Niels From: Roberto R
[mailto:[EMAIL PROTECTED] Hi. Would it be
possible for you to provide an example of what you'd like the DataMapper to do
(select, insert, update, and delete scenarios)? On 6/15/05, Yes, that is also the
answer I was looking for but nothing is mentioned |
