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 6797351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:35:54+00:00 2026-05-26T18:35:54+00:00

I am stacked. I would like to replace direct use of sql in favor

  • 0

I am stacked. I would like to replace direct use of sql in favor of mybatis faramework.
I would like to select list of accounts with filled properties map.

But lets start from the beginning, first Account class

public class Account {
     private int id;
     ...
     private Map<String, String> properties;
     ...
     //setters / getters
}

Mapper interface for Account is obvious and mapping file contains selects

<select id="getAccountById" resultMap="account">
       select ... from account where id = #{id}
</select>

<select id="getAccountProperties" resultType=map>
       select * from properties where id=#{id}
</select>

First selection returns Account object, second java.util.Map contains column name / value pair.

I would like that each account object contain map with properties, so I iterate over list of accounts and selects its properties by id

for(Account account : accountList) {
    int id = account.getId();
    Map properites = mapper.getAccountProperties(id);
    account.setProperties(properties);
}

And basically it works, but for 200 accounts it takes about 2 minutes, and it is not acceptable.

I hope that using resultMap with collection will speed it up. But the question is how
to do it. How should resultMap="account" looks like

<resultMap id="account" type="Account">
   <id property="id" column="id">
   ...
   <collection property="properties" javaType="map" column="id" select="getAccountProperties" />
</resultMap>

In this case selected account object does not contain any properties.
The big question is: How to associate properties with account object?

  • 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-05-26T18:35:55+00:00Added an answer on May 26, 2026 at 6:35 pm

    If you use the following resultmap

    <resultMap id="account" type="Account">
        <result property="id" column="id">
        <result property="properties" column="id" select="getAccountProperties" />
    </resultMap>
    

    Then for each account MyBatis executes the getAccountProperties statement passing the value of the column id as a parameter, but you must allow to accept it in the select tag:

    <select id="getAccountProperties" resultClass="java.util.Map" parameterClass="java.lang.Integer" >
        select * from properties where id=#value#
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We use a cube built in SSAS and we would like to show the
I would like to replace in text-fragments like: <strong>Media Event &quot;New Treatment Options on
I would like to make a stacked area chart with prefuse similar to the
I am using qplot to create a stacked bar plot and would like to
I am trying to make a stacked geom_area plot, but would like to outline
I would like to produce a graph that has stacked bars of the Area
I would like to be able to produce a stacked line graph (similar to
I would like to have the vertical arrangement of colors in stacked bars match
I've decided to use the 960 grid for a project and would like some
I would like to create a stacked bar chart based on data from a

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.