Are there plans any plans to support UUID natively? I mean, I know that I can inplement id via Handlers but it´s too tedius to, in my XML mappers to be writing the jdbcType, javaType and typeHandler all over the place.

Since most modern databases already have support for UUIDs, it would be great that MyBatis "just work" with them.

Comment From: harawata

So, you have a type handler that works with most modern databases? Could you post it so that we can review it?

By the way, you should be able to register the type handler globally in the config instead of specifying typeHandler in each occurrence in your mappers.

<typeHandlers>
  <typeHandler javaType="java.util.UUID" handler="pkg.UUIDTypeHandler"/>
</typeHandlers>

Comment From: alexandremjacques

@harawata maybe I wrongly expressed myself. I don't mean I have an implementation that works with all DBs. I said that most DBs have support for UUIDs nowadays.

Having the mybatis.type-handlers-package defined in Spring Boot application.properties (or yaml), forces you to have to declare the type of id (in this case) on each mapping. For example:

...where id = #{id, javaType=java.util.UUID, jdbcType=OTHER, typeHandler=UUIDTypeHandler}

I've found/adapted a TypeHandler implementation that works for Postgres. If it's not as simple as I initially thought to implement a "generic" one (since for Postgres it was), then we can close this issue.

Comment From: harawata

The difficulty is that there can be multiple data types for users to store UUID. If you use PostgreSQL's UUID type, you may be using PreparedStatement#setObject() in your type handler, but this does not always work (setString() works better with other DBs, I think, but it does not work with PostgreSQL's UUID currently).

...where id = #{id, javaType=java.util.UUID, jdbcType=OTHER, typeHandler=UUIDTypeHandler}

This shouldn't be necessary unless you are using Map as parameter/result type. Here is a demo. https://github.com/harawata/mybatis-issues/tree/master/gh-1609 Please let me know if I am missing something.

Comment From: harawata

I'll close this as 'won't fix'. As I explained, the implementation depends on the column data type (e.g. varchar, binary, DB-specific) and it's relatively easy to write/use a custom type handler.