मेरे पास वर्तमान में क्रूड रिपोजिटरी में स्थापित एक नामित मूल क्वेरी है जहां मैं कुछ तालिकाओं में शामिल हूं और मुझे उस क्वेरी परिणाम को डीटीओ में मैप करने की आवश्यकता है।

select
event_id, replaced_by_match_id, scheduled, start_time_tbd, status, away_team_competitor_id, home_team_competitor_id, round_round_id, season_season_id, tournament_tournament_id, venue_venue_id,
competitorHome.competitor_id as home_competitor_competitor_id, competitorHome.abbreviation as home_competitor_competitor_abbreviation, competitorHome.country_code as home_competitor_ccountry_code, competitorHome.ioc_code as home_competitor_ioc_code, competitorHome.rotation_number as home_competitor_rotation_number, competitorHome.virtual as home_competitor_virtual,
competitorAway.competitor_id as away_competitor_competitor_id, competitorAway.abbreviation as away_competitor_competitor_abbreviation, competitorAway.country_code as away_competitor_ccountry_code, competitorAway.ioc_code as away_competitor_ioc_code, competitorAway.rotation_number as away_competitor_rotation_number, competitorAway.virtual as away_competitor_virtual,
homeTeamTranslation.competitor_competitor_id as home_team_translation_competitor_competitor_id, homeTeamTranslation.language_language_id as home_team_translation_language_language_id, homeTeamTranslation.competitor_name as home_team_translation_competitor_name, homeTeamTranslation.competitor_country as home_team_competitor_country,
awayTeamTranslation.competitor_competitor_id as away_team_translation_competitor_competitor_id, awayTeamTranslation.language_language_id as away_team_translation_language_language_id, awayTeamTranslation.competitor_name as away_team_translation_competitor_name, awayTeamTranslation.competitor_country as away_team_competitor_country
from "event" as e
left join competitor as competitorAway on competitorAway.competitor_id = e.away_team_competitor_id
left join competitor as competitorHome  on competitorHome.competitor_id  = e.home_team_competitor_id
left join competitor_translation as homeTeamTranslation on competitorHome.competitor_id = homeTeamTranslation.competitor_competitor_id
left join competitor_translation as awayTeamTranslation on competitorAway.competitor_id = awayTeamTranslation.competitor_competitor_id
where awayTeamTranslation.language_language_id  = 'en' and homeTeamTranslation.language_language_id = 'en'

मैं परिणाम को डीटीओ कक्षाओं में मैप करने के लिए @SqlResultSetMapping एनोटेशन का उपयोग करने की कोशिश कर रहा हूं लेकिन असफल रहा।

मैंने इस तरह से मैपिंग सेट अप की है

@SqlResultSetMapping(
    name = "mapLocalizedEvent",
    classes = [ConstructorResult(
            targetClass = TranslatedLocalEvent::class,
            columns = arrayOf(
                    ColumnResult(name = "event_id"),
                    ColumnResult(name = "scheduled"),
                    ColumnResult(name = "start_time_tbd"),
                    ColumnResult(name = "status"),
                    ColumnResult(name = "replaced_by_match_id")
            )
    )]
)

और यह ठीक काम कर रहा है जहां इस्तेमाल किए गए सभी कॉलम रिसेट सरल प्रकार स्ट्रिंग या बूलियन हैं। यह इस तरह दिखने वाले TranslatedLocalEvent पर आपत्ति जताने के लिए मैप करता है

class TranslatedLocalEvent(
    val eventId: String? = null,
    val scheduled: String? = null,
    val startTimeTbd: Boolean? = null,
    val status: String? = null,
    val replacedByMatchId: String? = null
)

क्या कोई तरीका है जिससे मैं किसी जटिल वस्तु को मैप करने के लिए इस दृष्टिकोण का उपयोग कर सकता हूं? TranslatedLocalEvent ऑब्जेक्ट में कॉलम क्वेरी रिटर्न के कुछ हिस्सों से निर्मित TranslatedLocalCompetitor ऑब्जेक्ट शामिल होना चाहिए

class TranslatedLocalEvent(
    val eventId: String? = null,
    val scheduled: String? = null,
    val startTimeTbd: Boolean? = null,
    val status: String? = null,
    val replacedByMatchId: String? = null,
    val homeTeam: TranslatedLocalCompetitor? = null
)


public class TranslatedLocalCompetitor(
    val competitorId: String? = null
    val competitorName: String? = null
    val competitorCountry: String? = null
)
0
Luka Mišković 16 जिंदा 2020, 10:22

1 उत्तर

सबसे बढ़िया उत्तर

सबसे आसान तरीका जो मैं देख रहा हूं वह है आपके TranslatedLocalEvent कंस्ट्रक्टर सभी कॉलम स्वीकार करते हैं और कंस्ट्रक्टर में TranslatedLocalCompetitor ऑब्जेक्ट बनाते और असाइन करते हैं।

0
Robert Niestroj 16 जिंदा 2020, 12:03