2012-09-07 61 views
0

我正在嘗試使用多次使用相同參數的較大SQL語句來設置MyBatis接口。我的代碼是:mybatis參數問題

@Select({ 
"select cnfp_nr_years, cnfp_nr_credits, cnfp_credits_activities, cnfp_credits_studies, cnfp_credits_professional_evolution, cnfp_credits_programs_first_second, cnfp_credits_programs_third_fourth ", 
"from ", 
"(select cnfp_parameter_value as cnfp_nr_years ", 
"from cnfp_parameters ", 
"where cnfp_parameter_name='PARAM_NR_YEARS' ", 
"and CNFP_PARAMETER_START_DATE <= #{cnfpProcessingDate,jdbcType=DATE} ", 
"and (cnfp_parameter_end_date is null or cnfp_parameter_end_date >= #{cnfpProcessingDate,jdbcType=DATE})) as param1, ", 
"(select cnfp_parameter_value as cnfp_nr_credits ", 
"from cnfp_parameters ", 
"where cnfp_parameter_name='PARAM_NR_CREDITS' ", 
"and CNFP_PARAMETER_START_DATE <= #{cnfpProcessingDate,jdbcType=DATE} ", 
"and (cnfp_parameter_end_date is null or cnfp_parameter_end_date >= #{cnfpProcessingDate,jdbcType=DATE})) as param2, ", 
"(select coalesce(sum(cnfp_teacher_activity_cpt_equiv),0) as cnfp_credits_activities ", 
"from cnfp_teacher_activities ", 
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ", 
"and cnfp_teacher_activity_date_equiv <= #{cnfpProcessingDate,jdbcType=DATE}' ", 
"and cnfp_teacher_activity_date_expiry >= #{cnfpProcessingDate,jdbcType=DATE}) as activities, ", 
"(select coalesce(sum(cnfp_teacher_study_cpt_equiv), 0) as cnfp_credits_studies ", 
"from cnfp_teacher_studies ", 
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ", 
"and cnfp_institution_id is not null ", 
"and cnfp_teacher_study_date_equiv <= #{cnfpProcessingDate,jdbcType=DATE} ", 
"and cnfp_teacher_study_date_expiry >= #{cnfpProcessingDate,jdbcType=DATE}) as studies, ", 
"(select coalesce(sum(cnfp_teacher_study_cpt_equiv), 0) as cnfp_credits_professional_evolution ", 
"from cnfp_teacher_studies ", 
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ", 
"and cnfp_professional_level_id is not null ", 
"and cnfp_teacher_study_date_equiv <= #{cnfpProcessingDate,jdbcType=DATE} ", 
"and cnfp_teacher_study_date_expiry >= #{cnfpProcessingDate,jdbcType=DATE}) as professional_evolution, ", 
"(select coalesce(sum(case when cnfp_program_categories_code in (1,2) then cnfp_program_module_cpt_equiv else 0 end), 0) as cnfp_credits_programs_first_second, ", 
"coalesce(sum(case when cnfp_program_categories_code in (3,4) then cnfp_program_module_cpt_equiv else 0 end), 0) as cnfp_credits_programs_third_fourth ", 
"from cnfp_teacher_learning_activities ", 
"left join cnfp_teacher_learning_activities_x_program_modules on cnfp_teacher_learning_activities.cnfp_teacher_learning_activity_id = cnfp_teacher_learning_activities_x_program_modules.cnfp_teacher_learning_activity_id ", 
"left join cnfp_program_modules on cnfp_teacher_learning_activities_x_program_modules.cnfp_program_module_id = cnfp_program_modules.cnfp_program_module_id ", 
"left join cnfp_programs on cnfp_program_modules.cnfp_program_id = cnfp_programs.cnfp_program_id ", 
"left join cnfp_program_categories on cnfp_programs.cnfp_program_categories_id = cnfp_program_categories.cnfp_program_categories_id ", 
"where cnfp_person_id = #{cnfpPersonId,jdbcType=BIGINT} ", 
"and CNFP_TEACHER_LEARNING_ACTIVITY_STATUS = 1 ", 
"and CNFP_TEACHER_LEARNING_ACTIVITY_GRAD_DATE <= #{cnfpProcessingDate,jdbcType=DATE} ", 
"and CNFP_TEACHER_LEARNING_ACTIVITY_EXPIRY_DATE >= #{cnfpProcessingDate,jdbcType=DATE}) as learning_activities" 
}) 
@Results({ 
    @Result(column="cnfp_nr_years", property="cnfpParamVerifYears", jdbcType=JdbcType.BIGINT), 
    @Result(column="cnfp_nr_credits", property="cnfpParamCreditsAcc", jdbcType=JdbcType.BIGINT), 
    @Result(column="cnfp_credits_activities", property="cnfpCreditsActivities", jdbcType=JdbcType.BIGINT), 
    @Result(column="cnfp_credits_studies", property="cnfpCreditsStudies", jdbcType=JdbcType.BIGINT), 
    @Result(column="cnfp_credits_professional_evolution", property="cnfpCreditsProfessionalEvolution", jdbcType=JdbcType.BIGINT), 
    @Result(column="cnfp_credits_programs_first_second", property="cnfpCreditsProgramsFirstSecondCat", jdbcType=JdbcType.BIGINT), 
    @Result(column="cnfp_credits_programs_third_fourth", property="cnfpCreditsThirdFourthCat", jdbcType=JdbcType.BIGINT) 
}) 
CptCalculator selectResults(@Param("cnfpPersonId")Long cnfpPersonId, @Param("cnfpProcessingDate")Date cnfpProcessingDate); 

但一直收到異常:

java.sql.SQLException: Parameter index out of range (7 > number of parameters, which is 6).] with root cause 

java.sql.SQLException中:參數索引超出範圍(7>的參數號,它是6)。

我不知所措。任何幫助,將不勝感激

回答

0

結果,你期待7個元素,你只得到六。直接在DB客戶端中測試您的查詢以檢查輸出。