MyBatis recipes

In addition to simplifying the database programming, MyBatis provides various features that are very useful for implementing some common tasks, such as loading the table rows page by page, storing and retrieving CLOB/BLOB type data, and handling enumerated type values, among others. Let us have a look at a few of these features.

Handling enumeration types

MyBatis supports persisting enum type properties out of the box. Assume that the STUDENTS table has a column gender of the type varchar to store either MALE or FEMALE as the value. And, the Student object has a gender property that is of the type enum as shown in the following code:

public enum Gender 

By default, MyBatis uses EnumTypeHandler to handle enum type ...

Get Java Persistence with MyBatis 3 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.