|
Hi,
I'm using ibatis 2.3. Normally, I can create a result map to map my Java fields to database columns ... <resultMap id = "userPromotionRuleResultMap" class="com.lvcva.model.beans.UserPromotionRule"> <result property = "id" column = "id"/> ... However, I have a bean with dozens of fields. They all contain the same name as the database column. Is there any way I can tell ibatis to just map the database column to a Java field of the same name without explicitly typing everything out? Thanks, - Dave |
|
Hi,
did you already try to use the implicit map? In the sql map statement, select column name using the 'as' keyword renaming them to POJO's fields, something like <select id="XXX" resultClass="com.lvcva.model.beans.UserPromotionRule"> SELECT a.id as id, a.named_column_1 as namedColumn1, b.named_column_2 as namedColumn2, FROM a, b WHERE .... </select> It should help you reduce the code in the xml. Hope it helps, good luck! Simo http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Thu, Sep 9, 2010 at 7:16 PM, laredotornado <[hidden email]> wrote: > Hi, > > I'm using ibatis 2.3. Normally, I can create a result map to map my > Java fields to database columns ... > > <resultMap id = "userPromotionRuleResultMap" > class="com.lvcva.model.beans.UserPromotionRule"> > <result property = "id" column = "id"/> > ... > > However, I have a bean with dozens of fields. They all contain the > same name as the database column. Is there any way I can tell ibatis > to just map the database column to a Java field of the same name > without explicitly typing everything out? > > Thanks, - Dave |
|
I believe this method fails if you are using constructor args.
So immutable datamodels won't be able to use this approach. On Thu, Sep 9, 2010 at 2:02 PM, Simone Tripodi <[hidden email]> wrote: > Hi, > did you already try to use the implicit map? In the sql map statement, > select column name using the 'as' keyword renaming them to POJO's > fields, something like > > <select id="XXX" resultClass="com.lvcva.model.beans.UserPromotionRule"> > SELECT > a.id as id, > a.named_column_1 as namedColumn1, > b.named_column_2 as namedColumn2, > FROM > a, b > WHERE > .... > </select> > > It should help you reduce the code in the xml. > Hope it helps, good luck! > Simo > > http://people.apache.org/~simonetripodi/ > http://www.99soft.org/ > > > > On Thu, Sep 9, 2010 at 7:16 PM, laredotornado <[hidden email]> wrote: >> Hi, >> >> I'm using ibatis 2.3. Normally, I can create a result map to map my >> Java fields to database columns ... >> >> <resultMap id = "userPromotionRuleResultMap" >> class="com.lvcva.model.beans.UserPromotionRule"> >> <result property = "id" column = "id"/> >> ... >> >> However, I have a bean with dozens of fields. They all contain the >> same name as the database column. Is there any way I can tell ibatis >> to just map the database column to a Java field of the same name >> without explicitly typing everything out? >> >> Thanks, - Dave > |
|
absolutely right :)
http://people.apache.org/~simonetripodi/ http://www.99soft.org/ On Thu, Sep 9, 2010 at 9:09 PM, Tim <[hidden email]> wrote: > I believe this method fails if you are using constructor args. > So immutable datamodels won't be able to use this approach. > > On Thu, Sep 9, 2010 at 2:02 PM, Simone Tripodi <[hidden email]> wrote: >> Hi, >> did you already try to use the implicit map? In the sql map statement, >> select column name using the 'as' keyword renaming them to POJO's >> fields, something like >> >> <select id="XXX" resultClass="com.lvcva.model.beans.UserPromotionRule"> >> SELECT >> a.id as id, >> a.named_column_1 as namedColumn1, >> b.named_column_2 as namedColumn2, >> FROM >> a, b >> WHERE >> .... >> </select> >> >> It should help you reduce the code in the xml. >> Hope it helps, good luck! >> Simo >> >> http://people.apache.org/~simonetripodi/ >> http://www.99soft.org/ >> >> >> >> On Thu, Sep 9, 2010 at 7:16 PM, laredotornado <[hidden email]> wrote: >>> Hi, >>> >>> I'm using ibatis 2.3. Normally, I can create a result map to map my >>> Java fields to database columns ... >>> >>> <resultMap id = "userPromotionRuleResultMap" >>> class="com.lvcva.model.beans.UserPromotionRule"> >>> <result property = "id" column = "id"/> >>> ... >>> >>> However, I have a bean with dozens of fields. They all contain the >>> same name as the database column. Is there any way I can tell ibatis >>> to just map the database column to a Java field of the same name >>> without explicitly typing everything out? >>> >>> Thanks, - Dave >> > |
|
Administrator
|
In reply to this post by Tim
Actually, they can. You'll just have to map the results to the private field names.
On Thu, Sep 9, 2010 at 1:09 PM, Tim <[hidden email]> wrote: I believe this method fails if you are using constructor args. |
| Powered by Nabble | Edit this page |
