java.sql2 annotation usage

Lukas Eder lukas.eder at
Mon Oct 23 18:41:13 UTC 2017


2017-10-20 21:17 GMT+02:00 Lance Andersen <lance.andersen at>:

> Hi Philippe,
> So we are all on the same page,  you are talking about using the
> Converter annotation which requires the class to  implement
> AttributeConveter.
> This is fairly flexible.

> I can see a use case for  Hibernate UserTypes, but not sure I am convinced
> that is a must for the initial release.
> Lukas,  Can you provide an example from JOOQ comparing to the JPA model

jOOQ also has an org.jooq.Converter<T, U> type that works just like JPA's
AttributeConverter (it is not passed to a data type through an annotation,
but through explicit type building API, but that's a detail):

The Converter SPI is an easy  entry point for simple data type conversion
that works in most cases. But as Philippe mentioned, often a more low level
SPI is needed, which has access to the underlying JDBC API. In jOOQ, this
is org.jooq.Binding<T, U> (which may contain a Converter):

It offers interception points for 7 distinct JDBC-facing operations, which
include all the patterns:

- Getting a value out of a ResultSet
- Getting a value out of a SQLInput
- Getting a value out of a CallableStatement
- Registering an OUT parameter on a CallableStatement
- Setting a value on a SQLOutput
- Setting a value on a PreparedStatement
- Generating the SQL string for the bind variable (e.g. "?" or "CAST(? AS
MY_TYPE)", etc.)

This has worked very well for every single-valued data type that I've seen
so far. Hibernate's UserType is somewhat similar, although more limited in
what it can do, and in how it can be evolved backwards compatibly.

A minor feature of this SPI is its capability to be evolved backwards
compatibly, as every SPI method contains an "IN OUT" argument object,
instead of a fixed set of primitive typed arguments / return types. Some
thoughts about that here:

I think that such an SPI could be designed for the new JDBC API as well.

Hope this helps,

More information about the jdbc-spec-discuss mailing list