Tuesday, 15 September 2015

java - jOOQ : compare uuid(from postgresql) and string(user id in class) -



java - jOOQ : compare uuid(from postgresql) and string(user id in class) -

my backend postgresql. trying write simple function fetch info database, using jooq records. dao table written me. problem facing comparing of uuid in db , string provided function.

public correspondence fetchbyexternalid(string externalid) { correspondencerecord correspondencerecord = create.fetchone(tables.correspondence, tables.correspondence.userid.eq(externalid));

correspondence.userid uuid , externalid string; operator eq 1 not able implement here, has worked me on previous occasions.

the error shown : cannot resolve method 'eq(java.lang.string)'

when referred jooq site help show 'eq' operator suggests used!

can help me alternative or tell me went wrong?

jooq type safe api, cannot compare uuid types string types using eq(), because eq() method uses generic <t> type of correspondence.userid column, uuid:

tablefield<..., java.util.uuid> userid = ... generating uuid bind value in java client

you either have supply externalid in form of uuid type, e.g.:

correspondence.userid.eq(uuid.fromstring(externalid))

... or, allow jooq convert type you:

correspondence.userid.eq(correspondence.userid.getdatatype().convert(externalid))

both of above equivalent.

generating uuid bind value in database

you can defer type conversion work database casting (which result in cast(? uuid) beingness rendered:

correspondence.userid.eq(dsl.cast(externalid, uuid.class));

... or coercing variable adhere uuid type (trusting database can implicitly convert varchar type uuid type):

correspondence.userid.eq(dsl.coerce(dsl.val(externalid), uuid.class));

java postgresql jooq

No comments:

Post a Comment