concept custom type handler in category iBatis

appears as: custom type hdlers, custom type handler
iBatis in Action

This is an excerpt from Manning's book iBatis in Action.

In chapter 12, you will learn more about how to build custom type handlers to deal with these sorts of situations, so we will not go into much more detail here. To deal with this situation, you need to create two classes: a custom type handler and a type handler callback.

If you write a custom type handler, you need to tell iBATIS how and when to use them. You do that by using the <typeHandler> element and telling it what it is translating between: the jdbcType and the javaType. In addition, the callback class that is used to manage the type handler is required.

Note that in most cases you’ll never need to write a custom type handler. iBATIS has prebuilt type handlers to deal with 99 percent of the cases. Usually a custom type handler is only necessary if you’re using an odd database or driver that does not support the typical type mapping common to most databases. Avoid writing custom type handlers if you can, to keep your application simple.

Custom type handlers are by far the most common form of extension in iBATIS. This is mostly due to the wide range of nonstandard features and data types supported by relational database systems. In the remaining sections, we discuss other forms of extension that are rarer but still useful to know about.

12.2. Working with custom type handlers

As much as we’d all like relational database management systems to be standard, unfortunately they just aren’t. They all tend to implement their own SQL extensions, as well as their own data types. Although more common data types like binary large objects (BLOBs) and character large objects (CLOBs) are supported by most relational databases, they are usually handled differently by each driver. Therefore it is difficult for the iBATIS framework to support all databases using a single type handler implementation. To deal with these situations, iBATIS supports custom type handlers that allow you to customize the way that certain types are handled. Using a custom type handler, you can tell iBATIS how to map relational database types to Java types. You can even override the built-in type handlers. This section will explain how.