Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:09:41+00:00 2026-06-04T10:09:41+00:00

This is a part of my XML configuration for MyBatis. <sql id=selectElementWithAttributes> SELECT e.id

  • 0

This is a part of my XML configuration for MyBatis.

<sql id="selectElementWithAttributes">
    SELECT
    e.id as id,
    e.title as title,
    e.type as type,
    e.date as date,
    e.ownerid as ownerid,
    a.attributeid as attributeid,
    a.value as value,
    a.type as a_type
    FROM
    test_element as a
    LEFT JOIN
    test_elementattributes as a
    ON
    e.id
    = a.parentid
</sql>

now I use a resultMap to map the columns to my Object.

<resultMap type="Element" id="rmElement">
    <id property="id" column="id" />
    <result property="title" column="title" />
    <result property="type" column="type" />
    <result property="date" column="date" />
    <result property="ownerid" column="ownerid" />
    <collection property="attributes" ofType="Attribute">
        <id property="{id=parentid,attributeid=attributeid}" />
        <result property="key" column="attributeid" />
        <result property="value" column="value" />
    </collection>
</resultMap>

The problem is, I have to collections in my Element object.
Both Collections contain Attributes.
The difference is the type (mapped to a_type) of the attributes.
Depending on this type I like to have the Attribute in collection 1 or collection 2.
I played around with the discriminator, but don’t really understand what I was doing and it doesn’t work…

This is the idea, but how do I switch the collections depending on a_type?

<resultMap type="Element" id="rmElement">
    <id property="id" column="id" />
    <result property="title" column="title" />
    <result property="type" column="type" />
    <result property="date" column="date" />
    <result property="ownerid" column="ownerid" />
    <collection property="attributes" ofType="Attribute">
        <id property="{id=parentid,attributeid=attributeid}" />
        <result property="key" column="attributeid" />
        <result property="value" column="value" />
    </collection>
    <collection property="attributesOther" ofType="Attribute">
        <id property="{id=parentid,attributeid=attributeid}" />
        <result property="key" column="attributeid" />
        <result property="value" column="value" />
    </collection>
</resultMap>

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:09:42+00:00Added an answer on June 4, 2026 at 10:09 am

    Never used this stuff, so just an idea. Modify the query to return two sets of attributes, then filter out the NULLs on the reading end?

    <sql id="selectElementWithAttributes">
        SELECT
        e.id as id,
        e.title as title,
        e.type as type,
        e.date as date,
        e.ownerid as ownerid,
        CASE WHEN a.type = 'attribute1' THEN a.attributeid ELSE NULL END as attribute1id,
        CASE WHEN a.type = 'attribute2' THEN a.attributeid ELSE NULL END as attribute2id,
        a.value as value,
        a.type as a_type
        FROM
        test_element as a
        LEFT JOIN
        test_elementattributes as a
        ON
        e.id
        = a.parentid
    </sql>
    

    Then put your two different collections in the resultmap for attribute1 and attribute2. Both collections will get the full set, but the values will be NULL for the attributes that don’t belong to the set. Or use a different flag if NULL is a legit value. Even better if there is a way to skip putting NULLs into the collection.

    Maybe a silly suggestion, but who knows? Perhaps a hint to a different approach?
    [Oh, and other than the obvious: create two queries]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my parent pom.xml (part of it) in a multi-module project: ... <build>
Currently, we use a giant configuration object that is serialized to/from XML. This has
I've this configuration in the hibernate.cfg.xml: <?xml version=1.0 encoding=utf-8 ?> <hibernate-configuration xmlns=urn:nhibernate-configuration-2.2> <session-factory> <property
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
This part of my code is used to award a grade to a student
This part of an app that I am working on, I have the following
It seems that this part of my code is where the exception occurs: c
For some reasons this part where I fetch JSON data from following url will
I have this part of the function : $jQ('.product-collateral .product-tabs li').each(function(index){ $jQ(this).attr('id', $jQ(this).find('h3').attr('class')); if(index
You may skip this part: I am creating an application where the client needs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.