O'Reilly logo

Java Persistence with MyBatis 3 by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ResultMaps

ResultMaps are used to map the SQL SELECT statement's results to JavaBeans properties. We can define ResultMaps and reference this resultMap query from several SELECT statements. The MyBatis ResultMaps feature is so powerful that you can use it for mapping simple SELECT statements to complex SELECT statements with one-to-one and one-to-many associations.

Simple ResultMaps

A simple resultMap query that maps query results to the Student JavaBeans is as follows:

<resultMap id="StudentResult" type="com.mybatis3.domain.Student"> <id property="studId" column="stud_id"/> <result property="name" column="name"/> <result property="email" column="email"/> <result property="phone" column="phone"/> </resultMap> <select id="findAllStudents" resultMap="StudentResult" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required