Hello, and sorry for the delay
2015-01-25 4:03 GMT+01:00 Oliver Wahl <[email protected]>:
> I've searched hi and low on the net to figure out an easy way to use an
> java.util.UUID type as record id. As this is a MariaDB instance I used a
> binary(16) field as storage.
>
> Now on to the problem: I tried using a definition of a SQLDataType.UUID
> mapping as I understood that this is internally mapped to a java.util.UUID.
> The configuration used was:
>
> <forcedType>
>
> <name>UUID</name>
>
> <expression>(?i:.*\..*_uuid)$/expression>
>
> </forcedType>
>
>
> Generated code did compile but fetching data always resulted in NULL
> values instead of the correctly stored UUIDs (and yes newRecord/store did
> work). A little debugging showed that default converter was trying to parse
> a String into a UUID and obviously the regex matcher didn't work on the
> binary data.
>
Yes, this currently only works if the database contains a VARCHAR
representation of your UUID. I wonder if we can make the "forcedType-only"
configuration work also for BINARY representations.
>
> Switching to a
>
> <customType>
>
> <name>java.util.UUID</name>
>
> <converter>org.zbra.domain.UUIDConverter</converter>
>
> </customType>
>
> and
>
> <forcedType>
>
> <name>java.util.UUID</name>
>
> <expression>(?i:.*\..*_uuid)$/expression>
> </forcedType>
>
> implementing very straight forward
>
> import org.jooq.Converter;
>
> import java.nio.ByteBuffer;
> import java.util.UUID;
>
> public class UUIDConverter implements Converter<byte[], UUID> {
>
> private static final long serialVersionUID = 8213839434240264996L;
>
> @Override
> public UUID from(byte[] bytes) {
>
> did work and fetching now returns correct values.
>
Yes, that's what we're doing in our integration tests for MySQL UUID
columns represented as BINARY(16).
> Was my assumption wrong that SQLDataType.UUID can be mapped to a
> binary(16)? Or how would it have to be configured? Feels to me that I
> rewrote boiler plate code...
>
We don't support that out of the box yet. Yes, it's boiler plate code, but
there are tons of possible <T> / <U> pairs that could be useful to some
users. People might even implement UUIDs as two BIGINT columns. We're
waiting to see how adoption for org.jooq.Binding goes, and then, we might
host community-contributed implementations. Shipping them with the core
deliverable seems like overkill, and at the same time, we'd still be
missing *some* pair of T/U.
I hope this helps,
Lukas
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.