SteelReed

Search

Search posts, questions…

JPA & HibernateQuestion 23 / 24

Junior

How do resultType and resultMap differ in MyBatis? How do you map nested objects and collections?

Short answer

resultType lets MyBatis map columns to fields by name on its own, fine for flat results. resultMap is a hand-declared mapping, used when names differ or you need nested objects and child lists built from a JOIN.

yesnoFlat result,columns match fields?resultTyperesultMapid: merge JOIN rowscollection: child list

3 points to say:

  1. Turn on map-underscore-to-camel-case to need fewer resultMaps.
  2. Building a child List from a JOIN needs a resultMap.
  3. <id> decides how JOIN rows are merged.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.