Selecting a nested object using mybatis annotations

I have a POJO, like this one

class foo
{
private String id;
private String attribute;
private Map<String, String> dataMap;
}

And my data model

Table Item
- INT id
- CHAR attribute

// save dataMap as a key-value pair

Table Data
- INT id
- CHAR key
- CHAR value

Now I want to combine below 2 queries

1st request:

@Select("select * from Item where attribute=#{attribute}"
public List<Item> getItemList(@Param("attribute") String attribute);

another request to get all key-value pairs for a given id

How to get one request that sets the attribute, retrieves the id list and populates the nested object (dataMap)

// walked through @Results, @Result ..

+3
source share
1 answer

This situation can be resolved in myBatis in two ways:

  • selects nested - you retrieve a list of elements and for each run a separate selection to obtain data;
  • - , , myBatis ;

, " n + 1". - .

MyBatis , XML. Java , ( , Java-, ​​ : IBatis (MyBatis): : , , , N + 1 ).

+8

All Articles