Oh, I see. So there are two issues.
1. jOOQ indeed has a bug: https://github.com/jOOQ/jOOQ/issues/5846.
2. Your usage of selectFrom() could be improved
Right now, from what I understand, you're using the plain SQL API, where
you're passing only the table name to the selectFrom() method. This works
of course, but then jOOQ will materialise the database type byte[] in your
records, i.e. the type it receives automatically from JDBC.
You could work around this problem by either:
- Explicitly selecting your column through
select(CEntityCarPostingLink.ObjectID)
.from(CEntityCarPostingLink.TableName)
- Explicitly applying the converter on your getValue call:
a.getValue(CEntityCarPostingLink.ObjectID,
CEntityCarPostingLink.ObjectID.getDataType().getConverter())
You should probably prefer the first solution, as SELECT * should be
avoided for performance reasons anyway. More info about that here:
https://blog.jooq.org/2017/03/08/many-sql-performance-problems-stem-from-unnecessary-mandatory-work/
I hope this helps,
Lukas
2017-07-11 12:22 GMT+02:00 <[email protected]>:
> Here is the stack trace:
>
> java.lang.ClassCastException: [B cannot be cast to name.liwuest.data.CUUID
> at name.liwuest.car.CEntityCarPosting.getLinks(CEntityCarPosting.java:
> 149) ~[bin/:?]
> at name.liwuest.car.CCarPosting.run(CCarPosting.java:57) [bin/:?]
> at java.lang.Thread.run(Thread.java:745) [?:1.8.0_121]
>
>
>
>
> The CCE occurs right after jooq's get-method. Actually, when I invoke
>
> Object o = a.get(CEntityCarPostingLink.ObjectID);
>
>
>
> it works and o is of type byte[], while the method signature reads "CUUID
> get(Field)".
>
>
>
> Am Freitag, 7. Juli 2017 21:09:48 UTC+2 schrieb Bjoern Wuest:
>>
>> I think this is a bug.
>>
>> Have following table definition:
>>
>> public final static Table TableName = DSL.table(DSL.name(CEntityCarP
>> ostingLink.class.getSimpleName()));
>> public final static Field<CUUID> ObjectID = DSL.field(DSL.name(
>> "ObjectID"), SQLDataType.BLOB.nullable(false).asConvertedDataType(new
>> CUUIDConverter())); private final CUUID m_ObjectID;
>> JooqContext.createTableIfNotExists(TableName)
>> .column(ObjectID)
>> .constraints(DSL.constraint(TableName.toString() + "_" +
>> ObjectID.toString()).primaryKey(ObjectID))
>> .execute();
>>
>>
>> The code for the converter is:
>>
>> public final class CUUIDConverter implements Converter<byte[], CUUID> {
>> @Override public CUUID from(byte[] T) { return T == null ? null : new
>> CUUID(T); }
>> @Override public byte[] to(CUUID U) { return U == null ? null : U.
>> bytes(); }
>> @Override public Class<byte[]> fromType() { return byte[].class; }
>> @Override public Class<CUUID> toType() { return CUUID.class; }
>> }
>>
>>
>> When writing to the database, i.e. doing insert or update, I feed an
>> instance of CUUID and Jooq converts it to a byte-array and writes to
>> database.
>>
>> Yet, when reading from database, I get a ClassCastException.
>>
>> In the debugger I think I pinpointed to
>>
>> ...
>> 42 package org.jooq.impl;
>> ...
>> 113 @SuppressWarnings({ "rawtypes", "unchecked" })
>> 114 abstract class AbstractRecord extends AbstractStore implements Record
>> {
>> ...
>> 222
>> 223 @Override
>> 224 public final <T> T get(Field<T> field) {
>> 225 return (T) get(indexOrFail(fieldsRow(), field));
>> 226 }
>> 227
>> ...
>>
>> Shouldn't the get-Method invoke the Converter / Binding assigned to the
>> field, instead of doing simply a cast to T?
>>
>>
>> Best
>> Bjoern
>>
> --
> 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.
>
--
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.