select ID, MANUFACTURER, YEAR, MODEL, FEATURE_X from CARS_TABLE
union
select ID, MANUFACTURER, YEAR, MODEL, FEATURE_Y from CARS_TABLE
On 11/11/2014 6:31 PM, sandeep reddy wrote:
>
> Hi All,
> I have a scenario, where I SELECT all cars from CARS_TABLE and build a
> Car object. The challenge I'm facing is to build a List<Feature> from a
> single row. I tried several ways to this, but couldn't get what I needed.
>
> Below is the table and corresponding java class and XML Mapping. I
> appreciate if someone can help me resolve this.
>
> *CAR_TABLE*
> ID
> MANUFACTURER
> YEAR
> MODEL
> FEATURE_X
> FEATURE_Y
>
>
> *Car.java*
> private int id;
> private String manufacturer;
> private String year;
> private String model;
> private Features features;
>
>
> *Features.java*
> private List<Feature> feature;
>
>
> *Feature.java*
> private featureType;
>
>
>
> *Mapping*
>
>
> <resultMap id="BaseResultMap" type="com.eval.Car" >
>
> <id column="ID" property="ID" jdbcType="NUMERIC" />
> <result column="MANUFACTURER" property="manufacturer"
> jdbcType="VARCHAR" />
> <result column="YEAR" property="year" jdbcType="VARCHAR" />
> <result column="MODEL" property="model" jdbcType="VARCHAR" />
> <collection property="features" resultMap="FeaturesMap">
> </collection>
> </resultMap>
> <resultMap id="FeaturesMap" type="com.eval.Features" >
> <collection property="phoneRecord" ofType="com.eval.Feature">
> <*result property="featureType" column="feature1"/> *
> * <result property="featureType" column="feature2"/>*
> </collection>
> </resultMap>
> // I believe the above mapping is not the right way as both columns
> map to the same property and hence result in a single object. All I need
> is a List of features i.e List<Feature> where feature1 will be one
> Feature and feature2 will be another Feature.
>
>
> *SELECT QUERY*
> <select id="selectCars" resultMap="BaseResultMap" >
> select *
> from CARS_TABLE
> </select>
>
> --
> You received this message because you are subscribed to the Google
> Groups "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
mybatis-user...@googlegroups.com
> <mailto:
mybatis-user...@googlegroups.com>.
> For more options, visit
https://groups.google.com/d/optout.
--
Guy Rouillier
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com