|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Collection with composite key in XML mappingHi All,
Please could someone assist, I know this might be a silly question with a simple answer but I have tried all examples I have found, I have read the documentation and I have searched the forums and the internet but to no avail. I am using the latest beta version of iBatis 3 (beta 5) but had the same problem with beta 4. In iBatis v2x these complex key mappings worked fine. The documentation states: "Note: To deal with composite keys, you can specify multiple column names to pass to the nested select statement by using the syntax column=”{prop1=col1,prop2=col2}”. This will cause prop1 and prop2 to be set against the parameter object for the target nested select statement." However when I specify this with multiple columns for a collection the nested select is never run and no error is reported. In the referenced "select" I am accessing the parameters by #{param1Name} and #{param2Name} (where param1Name is the name of the first param etc..). If I remove this and only specify one parameter like column="col_1" then the referenced "select" is executed and the same param is used for both parameter mapping in the select. So the collection mapping can access the nested select and return a list of the correct type (albeit with a lot of incorrect rows due to not matching on the full complex key) but not when I have complex keys specified. What is the correct notation for using multiple columns for complex keys from a "collection" mapping. There are no examples in the documentation other than the excerpt above. I have also not found any workable examples on the internet. I have found references on the internet to accesing params with @{param} instead of #{param} which I have also tried with no luck. I have also tried specifying paramaterType="map" on the nested select with no results. ResultMap (XML file 1): <resultMap id="myResultMap" type="ResultClass"> <id property="id" column="id" /> <id property="clientId" column="client_id" /> <result property="someProp" column="some_prop" /> <collection property="myList" column="{id=id,clientId=client_id}" javaType="ArrayList" ofType="MyType" select="other.xml.namespace.MyTypeNS.nestedSelect" /> </resultMap> Select (XML file 2): <mapper namespace="other.xml.namespace.MyTypeNS"> <resultMap id="myTypeResultMap" type="MyType"> <!-- mapping of MyType --> </resultMap> <select id="nestedSelect" parameterType="map" resultMap="myTypeResultMap"> SELECT * FROM my_type_table WHERE other_id = #{id} AND client_id = #{client_id} </select> </mapper> Thanks for your time. Byron |
|
|
Re: Collection with composite key in XML mappingApologies, there is a typo in my last post the "select" should have read:
<select id="nestedSelect" parameterType="map" resultMap="myTypeResultMap"> SELECT * FROM my_type_table WHERE other_id = #{id} AND client_id = #{clientId} </select>
|
|
|
Re: Collection with composite key in XML mappingHi All,
Please if possible could someone assist me, I have been banging my head on this problem for near a week now and this is holding my project up seriously. I have tried everything I can think of and everything I can find. As soon as I include the composite key mapping of column=”{prop1=col1,prop2=col2}” in my xml mapping files the nested select is never executed and no error is reported/thrown. Am I doing something wrong in my mappings? I have also included the #{id, javaType=int, jdbcType=Numeric} but also with no luck. Kind Regards Byron
|
|
|
Re: Collection with composite key in XML mappingI have downloaded the latest trunk of iBatis 3 from SVN and did some
debugging. It appears as if the composite key notation "#{param1=col1,param2=col2}" is never passed when building the ResultMapping. This results in the composite key only being treated as a regular column. The composites List in ResultMapping is only ever initialized to a new ArrayList but never populated with anything meaningful. Then when applying the results from the ResultSet the isComposite() method always returns false and so the nested select is never executed. What is the process to follow to have this corrected? Regards Byron btymvios wrote: > Hi All, > > Please if possible could someone assist me, I have been banging my head on > this problem for near a week now and this is holding my project up > seriously. I have tried everything I can think of and everything I can find. > As soon as I include the composite key mapping of > column=”{prop1=col1,prop2=col2}” in my xml mapping files the nested select > is never executed and no error is reported/thrown. Am I doing something > wrong in my mappings? > > I have also included the #{id, javaType=int, jdbcType=Numeric} but also with > no luck. > > Kind Regards > Byron > > > btymvios wrote: > >> Apologies, there is a typo in my last post the "select" should have read: >> <select id="nestedSelect" parameterType="map" >> resultMap="myTypeResultMap"> >> SELECT * >> FROM my_type_table >> WHERE other_id = #{id} AND client_id = #{clientId} >> </select> >> >> >> btymvios wrote: >> >>> Hi All, >>> >>> Please could someone assist, I know this might be a silly question with a >>> simple answer but I have tried all examples I have found, I have read the >>> documentation and I have searched the forums and the internet but to no >>> avail. >>> >>> I am using the latest beta version of iBatis 3 (beta 5) but had the same >>> problem with beta 4. In iBatis v2x these complex key mappings worked >>> fine. >>> >>> The documentation states: >>> >>> "Note: To deal with composite keys, you can specify multiple column names >>> to pass to the nested select statement by using the syntax >>> column=”{prop1=col1,prop2=col2}”. This >>> will cause prop1 and prop2 to be set against the parameter object for the >>> target nested select statement." >>> >>> However when I specify this with multiple columns for a collection the >>> nested select is never run and no error is reported. In the referenced >>> "select" I am accessing the parameters by #{param1Name} and #{param2Name} >>> (where param1Name is the name of the first param etc..). >>> >>> If I remove this and only specify one parameter like column="col_1" then >>> the referenced "select" is executed and the same param is used for both >>> parameter mapping in the select. So the collection mapping can access the >>> nested select and return a list of the correct type (albeit with a lot of >>> incorrect rows due to not matching on the full complex key) but not when >>> I have complex keys specified. >>> >>> What is the correct notation for using multiple columns for complex keys >>> from a "collection" mapping. There are no examples in the documentation >>> other than the excerpt above. I have also not found any workable examples >>> on the internet. >>> >>> I have found references on the internet to accesing params with @{param} >>> instead of #{param} which I have also tried with no luck. I have also >>> tried specifying paramaterType="map" on the nested select with no >>> results. >>> >>> ResultMap (XML file 1): >>> <resultMap id="myResultMap" type="ResultClass"> >>> <id property="id" column="id" /> >>> <id property="clientId" column="client_id" /> >>> <result property="someProp" column="some_prop" /> >>> <collection property="myList" column="{id=id,clientId=client_id}" >>> javaType="ArrayList" ofType="MyType" >>> select="other.xml.namespace.MyTypeNS.nestedSelect" /> >>> </resultMap> >>> >>> Select (XML file 2): >>> <mapper namespace="other.xml.namespace.MyTypeNS"> >>> <resultMap id="myTypeResultMap" type="MyType"> >>> <!-- mapping of MyType --> >>> </resultMap> >>> <select id="nestedSelect" parameterType="map" >>> resultMap="myTypeResultMap"> >>> SELECT * >>> FROM my_type_table >>> WHERE other_id = #{id} AND client_id = #{client_id} >>> </select> >>> </mapper> >>> >>> Thanks for your time. >>> Byron >>> >>> >> > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-java-unsubscribe@... For additional commands, e-mail: user-java-help@... |
|
|
Re: Collection with composite key in XML mappingOpen a JIRA ticket. If you can attach a path and a test case that
would be even better. Jeff Butler On Thu, Nov 12, 2009 at 12:17 PM, Byron Tymvios <byron@...> wrote: > I have downloaded the latest trunk of iBatis 3 from SVN and did some > debugging. It appears as if the composite key notation > "#{param1=col1,param2=col2}" is never passed when building the > ResultMapping. This results in the composite key only being treated as a > regular column. The composites List in ResultMapping is only ever > initialized to a new ArrayList but never populated with anything meaningful. > Then when applying the results from the ResultSet the isComposite() method > always returns false and so the nested select is never executed. > > What is the process to follow to have this corrected? > > Regards > Byron > > btymvios wrote: >> >> Hi All, >> >> Please if possible could someone assist me, I have been banging my head on >> this problem for near a week now and this is holding my project up >> seriously. I have tried everything I can think of and everything I can >> find. >> As soon as I include the composite key mapping of >> column=”{prop1=col1,prop2=col2}” in my xml mapping files the nested select >> is never executed and no error is reported/thrown. Am I doing something >> wrong in my mappings? >> >> I have also included the #{id, javaType=int, jdbcType=Numeric} but also >> with >> no luck. >> >> Kind Regards >> Byron >> >> >> btymvios wrote: >> >>> >>> Apologies, there is a typo in my last post the "select" should have read: >>> <select id="nestedSelect" parameterType="map" >>> resultMap="myTypeResultMap"> >>> SELECT * >>> FROM my_type_table >>> WHERE other_id = #{id} AND client_id = #{clientId} >>> </select> >>> >>> >>> btymvios wrote: >>> >>>> >>>> Hi All, >>>> >>>> Please could someone assist, I know this might be a silly question with >>>> a >>>> simple answer but I have tried all examples I have found, I have read >>>> the >>>> documentation and I have searched the forums and the internet but to no >>>> avail. >>>> >>>> I am using the latest beta version of iBatis 3 (beta 5) but had the same >>>> problem with beta 4. In iBatis v2x these complex key mappings worked >>>> fine. >>>> >>>> The documentation states: >>>> >>>> "Note: To deal with composite keys, you can specify multiple column >>>> names >>>> to pass to the nested select statement by using the syntax >>>> column=”{prop1=col1,prop2=col2}”. This >>>> will cause prop1 and prop2 to be set against the parameter object for >>>> the >>>> target nested select statement." >>>> >>>> However when I specify this with multiple columns for a collection the >>>> nested select is never run and no error is reported. In the referenced >>>> "select" I am accessing the parameters by #{param1Name} and >>>> #{param2Name} >>>> (where param1Name is the name of the first param etc..). >>>> >>>> If I remove this and only specify one parameter like column="col_1" then >>>> the referenced "select" is executed and the same param is used for both >>>> parameter mapping in the select. So the collection mapping can access >>>> the >>>> nested select and return a list of the correct type (albeit with a lot >>>> of >>>> incorrect rows due to not matching on the full complex key) but not when >>>> I have complex keys specified. >>>> >>>> What is the correct notation for using multiple columns for complex keys >>>> from a "collection" mapping. There are no examples in the documentation >>>> other than the excerpt above. I have also not found any workable >>>> examples >>>> on the internet. >>>> >>>> I have found references on the internet to accesing params with @{param} >>>> instead of #{param} which I have also tried with no luck. I have also >>>> tried specifying paramaterType="map" on the nested select with no >>>> results. >>>> >>>> ResultMap (XML file 1): >>>> <resultMap id="myResultMap" type="ResultClass"> >>>> <id property="id" column="id" /> >>>> <id property="clientId" column="client_id" /> >>>> <result property="someProp" column="some_prop" /> >>>> <collection property="myList" column="{id=id,clientId=client_id}" >>>> javaType="ArrayList" ofType="MyType" >>>> select="other.xml.namespace.MyTypeNS.nestedSelect" /> >>>> </resultMap> >>>> >>>> Select (XML file 2): >>>> <mapper namespace="other.xml.namespace.MyTypeNS"> >>>> <resultMap id="myTypeResultMap" type="MyType"> >>>> <!-- mapping of MyType --> >>>> </resultMap> >>>> <select id="nestedSelect" parameterType="map" >>>> resultMap="myTypeResultMap"> >>>> SELECT * >>>> FROM my_type_table >>>> WHERE other_id = #{id} AND client_id = #{client_id} >>>> </select> >>>> </mapper> >>>> >>>> Thanks for your time. >>>> Byron >>>> >>>> >>> >>> >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-java-unsubscribe@... > For additional commands, e-mail: user-java-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-java-unsubscribe@... For additional commands, e-mail: user-java-help@... |
|
|
Re: Collection with composite key in XML mappingJIRA ticket opened, IBATIS-692.
Thanks
|
| Free embeddable forum powered by Nabble | Forum Help |