У меня есть файл сопоставления MyBatis
, который выглядит следующим образом -
<mapper namespace="ABCDEFGH">
<resultMap id="userWiseData" type="UserWiseData">
<id property="personId" column="person_id"/>
<association
property="mandatorySTC"
javaType="TypeWiseData"
resultSet="mandatorySTCResult">
<id property="typeId" column="type_id"/>
<result property="personId" column="person_id"/>
<collection
property="hrCompanyWiseData"
ofType="HRCompanyWiseData">
<id property="companyId" column="company_id"/>
<result property="companyCode" column="company_code"/>
<association
property="nonMidYear"
javaType="PeriodWiseData">
<id property="periodId" column="non_mid_year_period_id"/>
<collection
property="investmentDateWiseData"
ofType="InvestmentDateWiseData">
<id property="investmentDateId" column="non_mid_year_investment_date_id"/>
<collection
property="vestingDateWiseData"
ofType="VestingDateWiseData">
<id property="vestingDateId" column="non_mid_year_vesting_date_id"/>
<result property="awardDate" column="non_mid_year_award_date"/>
<result property="investmentDate" column="non_mid_year_investment_date"/>
<result property="vestingDate" column="non_mid_year_vesting_date"/>
<result property="amount" column="non_mid_year_amount"/>
<result property="returnAmount" column="non_mid_year_return_amount"/>
<result property="vestingAmount" column="non_mid_year_vesting_amount"/>
</collection>
</collection>
</association>
<association
property="midYear"
javaType="PeriodWiseData">
<id property="periodId" column="mid_year_period_id"/>
<collection
property="investmentDateWiseData"
ofType="InvestmentDateWiseData">
<id property="investmentDateId" column="mid_year_investment_date_id"/>
<collection
property="vestingDateWiseData"
ofType="VestingDateWiseData">
<id property="vestingDateId" column="mid_year_vesting_date_id"/>
<result property="awardDate" column="mid_year_award_date"/>
<result property="investmentDate" column="mid_year_investment_date"/>
<result property="vestingDate" column="mid_year_vesting_date"/>
<result property="amount" column="mid_year_amount"/>
<result property="returnAmount" column="mid_year_return_amount"/>
<result property="vestingAmount" column="mid_year_vesting_amount"/>
</collection>
</collection>
</association>
</collection>
</association>
</resultMap>
<select id="fetchUserWiseData" resultSets="mandatorySTCResult"
resultMap="userWiseData">
select '3520' as person_id
<!-- This gives results as shown in the CSV file below, which is - mandatorySTCResult -->
</select>
</mapper>
, и это классы, в которые я пытаюсь получить данные -
public class UserWiseData {
private String personId;
private TypeWiseData mandatorySTC;
// Setter-Getters
}
public class TypeWiseData {
private String typeId;
private String personId;
private List<HRCompanyWiseData> hrCompanyWiseData;
// Setter-Getters
}
public class HRCompanyWiseData {
private String companyId;
private String companyCode;
private PeriodWiseData nonMidYear;
private PeriodWiseData midYear;
// Setter-Getters
}
public class PeriodWiseData {
private String periodId;
private List<InvestmentDateWiseData> investmentDateWiseData;
// Setter-Getters
}
public class InvestmentDateWiseData {
private String investmentDateId;
private List<VestingDateWiseData> vestingDateWiseData;
// Setter-Getters
}
public class VestingDateWiseData {
private String vestingDateId;
private String awardDate;
private String investmentDate;
private String vestingDate;
private Double amount;
private Double returnAmount;
private Double vestingAmount;
// Setter-Getters
}
Результат запроса выглядит так -
person_id type_id company_id company_code non_mid_year_period_id non_mid_year_investment_date_id non_mid_year_vesting_date_id non_mid_year_award_date non_mid_year_investment_date non_mid_year_vesting_date non_mid_year_amount non_mid_year_return_amount non_mid_year_vesting_amount mid_year_period_id mid_year_investment_date_id mid_year_vesting_date_id mid_year_award_date mid_year_investment_date mid_year_vesting_date mid_year_amount mid_year_return_amount mid_year_vesting_amount
3520 3520-mandatory_stc 3520-mandatory_stc-EFGH EFGH 3520-mandatory_stc-EFGH-non_mid_year 3520-mandatory_stc-EFGH-non_mid_year-2018-01-01 3520-mandatory_stc-EFGH-non_mid_year-2018-01-01-2018-12-31 1/1/2018 1/1/2018 12/31/2018 16150 2374.05 18524.05
3520 3520-mandatory_stc 3520-mandatory_stc-ABCD ABCD 3520-mandatory_stc-ABCD-non_mid_year 3520-mandatory_stc-ABCD-non_mid_year-2018-01-01 3520-mandatory_stc-ABCD-non_mid_year-2018-01-01-2019-12-31 1/1/2018 1/1/2018 12/31/2019 6000 882 6882
3520 3520-mandatory_stc 3520-mandatory_stc-EFGH EFGH 3520-mandatory_stc-EFGH-non_mid_year 3520-mandatory_stc-EFGH-non_mid_year-2018-01-01 3520-mandatory_stc-EFGH-non_mid_year-2018-01-01-2019-12-31 1/1/2018 1/1/2018 12/31/2019 16150 2374.05 18524.05
3520 3520-mandatory_stc 3520-mandatory_stc-ABCD ABCD 3520-mandatory_stc-ABCD-non_mid_year 3520-mandatory_stc-ABCD-non_mid_year-2018-01-01 3520-mandatory_stc-ABCD-non_mid_year-2018-01-01-2020-12-31 1/1/2018 1/1/2018 12/31/2020 6000 882 6882
3520 3520-mandatory_stc 3520-mandatory_stc-EFGH EFGH 3520-mandatory_stc-EFGH-non_mid_year 3520-mandatory_stc-EFGH-non_mid_year-2018-01-01 3520-mandatory_stc-EFGH-non_mid_year-2018-01-01-2020-12-31 1/1/2018 1/1/2018 12/31/2020 16150 2374.05 18524.05
Я пробовал его с column
и foreignColumn
с тегами <association>
и <collection>
.Но он все равно дает тот же результат.
Я ожидаю, что мой результат будет выглядеть примерно так -
{
"userWiseData": [
{
"personId": "3520",
"mandatorySTC": {
"typeId": "3520-mandatory_stc",
"personId": "3520",
"hrCompanyWiseData": [
{
"companyId": "3520-mandatory_stc-ABCD",
"companyCode": "ABCD",
"monMidYear": {
"periodId": "3520-mandatory_stc-ABCD-non_mid_year",
"investmentDateWiseData": [
{
"investmentDateId": "3520-mandatory_stc-ABCD-non_mid_year-2018-01-01",
"vestingDateWiseData": [
{
"vestingDateId": "3520-mandatory_stc-ABCD-non_mid_year-2018-01-01-2019-12-31",
"awardDate": "01/01/2018",
"investmentDate": "01/01/2018",
"vestingDate": "12/31/2019",
"amount": "6000",
"returnAmount": "882",
"vestingAmount": "6882"
},
{
"vestingDateId": "3520-mandatory_stc-ABCD-non_mid_year-2018-01-01-2020-12-31",
"awardDate": "01/01/2018",
"investmentDate": "01/01/2018",
"vestingDate": "12/31/2020",
"amount": "6000",
"returnAmount": "882",
"vestingAmount": "6882"
}
]
}
]
},
"midYear": {}
},
{
"companyId": "3520-mandatory_stc-EFGH",
"companyCode": "EFGH",
"monMidYear": {
"periodId": "3520-mandatory_stc-EFGH-non_mid_year",
"investmentDateWiseData": [
{
"investmentDateId": "3520-mandatory_stc-EFGH-non_mid_year-2018-01-01",
"vestingDateWiseData": [
{
"vestingDateId": "3520-mandatory_stc-EFGH-non_mid_year-2018-01-01-2018-12-31",
"awardDate": "01/01/2018",
"investmentDate": "01/01/2018",
"vestingDate": "12/31/2018",
"amount": "16150",
"returnAmount": "2374.05",
"vestingAmount": "18524.05"
},
{
"vestingDateId": "3520-mandatory_stc-EFGH-non_mid_year-2018-01-01-2019-12-31",
"awardDate": "01/01/2018",
"investmentDate": "01/01/2018",
"vestingDate": "12/31/2019",
"amount": "16150",
"returnAmount": "2374.05",
"vestingAmount": "18524.05"
},
{
"vestingDateId": "3520-mandatory_stc-EFGH-non_mid_year-2018-01-01-2020-12-31",
"awardDate": "01/01/2018",
"investmentDate": "01/01/2018",
"vestingDate": "12/31/2020",
"amount": "16150",
"returnAmount": "2374.05",
"vestingAmount": "18524.05"
}
]
}
]
},
"midYear": {}
}
]
}
}
]
}
Однако все, что я получаю, это пустое значение для mandatorySTC
, какпоэтому -
{
"userWiseData": [
{
"mandatorySTC": null,
"personId": "3520"
}
]
}
Я использую -
<mybatis.version>3.5.0</mybatis.version>
<mybatis.spring.version>2.00</mybatis.spring.version>
Причина, по которой я пытаюсь использовать resultSet
, заключается в том, что мне нужно добавить больше ассоциаций, таких как mandatorySTC
и я хочу повторно использовать временные таблицы, созданные в <select id="fetchUserWiseData">
, чтобы получить данные и для других resultSets
.
Если я удаляю resultSet="mandatorySTCResult"
из <association>
и select '3520' as person_id
из запроса, я получаю данные, как и ожидалось.