Generator not using converter for forced types

747 views
Skip to first unread message

dbi...@gmail.com

unread,
Oct 8, 2013, 8:53:29 AM10/8/13
to jooq...@googlegroups.com
Hi,

I'm having a problem where if I configure forcedTypes, the field type is set correctly, but the associated converter is not applied.

Here is my configuration:

  <generator>
    <database>
      <name>org.jooq.util.postgres.PostgresDatabase</name>
      <includes>.*</includes>
      <excludes></excludes>
      <inputSchema>myschema</inputSchema>
      <customTypes>
        <customType>
          <name>com.fasterxml.jackson.databind.node.ObjectNode</name>
          <converter>com.mystuff.JsonConverter</converter>
        </customType>
      </customTypes>
      <forcedTypes>
        <forcedType>
          <name>com.fasterxml.jackson.databind.node.ObjectNode</name>
          <expressions>myschema\.table\.foo|myschema\.table\.bar</expressions>
        </forcedType>
      </forcedTypes>
    </database>
    <strategy><name>com.mystuff.PrefixGeneratorStrategy</name></strategy>
    <generate>
      <records>false</records>
    </generate>
    <target>
      <packageName>com.mystuff.sql</packageName>
      <directory>src/</directory>
    </target>
  </generator>


The fields are generated thusly:

    public final org.jooq.TableField<org.jooq.Record, com.fasterxml.jackson.databind.node.ObjectNode> FOO = createField("foo", org.jooq.impl.DefaultDataType.getDefaultDataType("json"), this);

Which, of course, doesn't compile. I have to manually add the .asConvertedDataType(new JsonConverter())

What am I doing wrong?

Thanks,
Dmitri

Lukas Eder

unread,
Oct 8, 2013, 9:04:22 AM10/8/13
to jooq...@googlegroups.com
This could be a bug. What jOOQ version are you using? Could you provide me with the DDL for the myschema.table?

Cheers
Lukas


2013/10/8 <dbi...@gmail.com>

--
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 jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Dmitri Bichko

unread,
Oct 8, 2013, 1:38:33 PM10/8/13
to jooq...@googlegroups.com
jOOQ 3.1.0

The actual table is:

CREATE SEQUENCE task_seq;
CREATE TABLE task (
  task_id   int4 PRIMARY KEY DEFAULT nextval('task_seq'),
  type      varchar(16) NOT NULL CHECK (type IN ('check', 'parse', 'index', 'merge', 'score', 'clear', 'store', 'stats')),
  status    varchar(16) NOT NULL CHECK (status IN ('wait', 'exec', 'done', 'fail', 'stop')),
  parent_id int4 REFERENCES task (task_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
  batch_id  int4 REFERENCES batch (batch_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
  search_id int4 REFERENCES search (search_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
  input     json,
  submitted timestamptz NOT NULL,
  initiated timestamptz,
  completed timestamptz
);
ALTER SEQUENCE litms.task_seq OWNED BY litms.task.task_id;
CREATE INDEX task_queue ON litms.task (type, submitted)
  WHERE status = 'wait';


'input' is the forced field. I get the same behavior with other columns and types, too.

Thanks,
Dmitri

Lukas Eder

unread,
Oct 17, 2013, 11:03:47 AM10/17/13
to jooq...@googlegroups.com, Dmitri Bichko
Hello Dmitri,

I'm sorry for the delay. I was able to reproduce this. There's actually quite a simple explanation for this. Forcing "unknown" types is simply not supported by jOOQ, right now. There are two things to be done:

Adding support for the PostgreSQL json data type:

Adding support for type rewriting when the "base" type is unknown to jOOQ:

I'm afraid I currently don't see an easy workaround short of:
- Patching the code generator at your side
- Patching the generated classes manually, at your side

Cheers
Lukas

2013/10/8 Dmitri Bichko <dbi...@gmail.com>

Lukas Eder

unread,
Oct 17, 2013, 11:25:10 AM10/17/13
to jooq...@googlegroups.com
As a matter of fact, I'm about to realise that supporting the json data type in PostgreSQL might not be so simple, as it doesn't work like other character data types. E.g. binding a variable without an actual cast is not possible. This means that even if #2789 was fixed, #2788 would be required for JSON data types to be supported...


2013/10/17 Lukas Eder <lukas...@gmail.com>

Lukas Eder

unread,
Oct 23, 2013, 10:50:24 AM10/23/13
to jooq...@googlegroups.com, Dmitri Bichko
Does the patching help? I.e. does jOOQ use the correct types of bind values?

2013/10/22 Dmitri Bichko <dbi...@gmail.com>
Thanks Lukas, I'll keep patching the generated classes for now.

Looking forward to more Postgres support in future releases!

Cheers,
Dmitri

Dmitri Bichko

unread,
Oct 23, 2013, 1:41:51 PM10/23/13
to Lukas Eder, jooq...@googlegroups.com
Yep, works quite well for what I need.

Inserts / updates only work with prepared statements, with static statements I end up with just a toString() of the value (at least for hstore/HashMap, I haven't tried it with JSON), which, of course, postgres doesn't understand. I think that's expected, though?

Dmitri

Lukas Eder

unread,
Oct 24, 2013, 11:46:15 AM10/24/13
to Dmitri Bichko, jooq...@googlegroups.com
Hi Dmitri,

Unfortunately, I have to say that not much qualifies as working as expected with PostgreSQL's advanced data types and the PostgreSQL JDBC driver. From my experience, there is always quite a bit of tweaking involved in that area - at least before jOOQ formally supports these types.

Cheers
Lukas

2013/10/23 Dmitri Bichko <dbi...@gmail.com>

Lukas Eder

unread,
Jul 17, 2017, 4:51:11 AM7/17/17
to jOOQ User Group
jOOQ 3.10 will now finally pattern-match also "unknown" types (types that jOOQ is not aware of, such as JSON), including user-defined types:
Lukas

2013/10/23 Dmitri Bichko <dbi...@gmail.com>


2013/10/22 Dmitri Bichko <dbi...@gmail.com>

2013/10/8 Dmitri Bichko <dbi...@gmail.com>
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages