Hello Adam,
2014-02-11 18:36 GMT+01:00 Adam <[email protected]>:
> Hi,
>
> I've been experimenting with jOOQ and, first of all, I have to say I'm
> very impressed so far. There just seems to be one snag that I've
> encountered regarding using H2's in-memory database alongside the jOOQ code
> generator, in that it only generates org.jooq.impl.TableRecordImplclasses for
> all tables rather than updatable records.
>
> The output from the code generator prints things like this:
>
> Feb 11, 2014 5:16:54 PM org.jooq.util.DefaultRelations info
> INFO: Ignoring primary key : constraint_4(column unavailable)
> Feb 11, 2014 5:16:54 PM org.jooq.util.DefaultRelations info
> INFO: Ignoring primary key : constraint_47(column unavailable)
>
> On closer inspection, it seems that the column is unavailable because the
> code in org.jooq.util.h2.H2Database#loadPrimaryKeys is failing to extract
> the primary key ColumnDefinition from its table by column name:
>
> 1 TableDefinition table = getTable(schema, tableName);
> 2 if (table != null) {
> 3 String[] columnNames = columnList.split("[,]+");
> 4
> 5 for (String columnName : columnNames) {
> 6 relations.addPrimaryKey(primaryKey,
> table.getColumn(columnName));
> 7 }
> 8 }
>
> The column name is coming in upper case but this doesn't agree with the
> TableDefinition. If I change the call to table.getColumn(columnName)(line 6
> above) to be table.getColumn(columnName,
> true) then it works perfectly and generates updatable table records as
> I'd expect.
>
> I've had to extend the H2Database class and override the
> loadPrimaryKeysmethod to fix this, but, given that nobody else seems to have
> this problem,
> I can't help feeling I'm missing something and there must be a better way
> to handle this case-sensitivity issue. Is there a less cumbersome way to
> get code generation to work with H2 or is this actually a bug?
>
Yes, that patch would be a workaround for the issue you're having, but I
wouldn't recommend this. Can you provide me with the output of this query
here:
SELECT "INFORMATION_SCHEMA"."CONSTRAINTS"."TABLE_SCHEMA",
"INFORMATION_SCHEMA"."CONSTRAINTS"."TABLE_NAME",
"INFORMATION_SCHEMA"."CONSTRAINTS"."COLUMN_LIST",
"INFORMATION_SCHEMA"."CONSTRAINTS"."CONSTRAINT_NAME"FROM
"INFORMATION_SCHEMA"."CONSTRAINTS"WHERE
("INFORMATION_SCHEMA"."CONSTRAINTS"."TABLE_SCHEMA" IN ('PUBLIC') --
Replace with actual schemaAND
"INFORMATION_SCHEMA"."CONSTRAINTS"."CONSTRAINT_TYPE" = 'PRIMARY
KEY')ORDER BY "INFORMATION_SCHEMA"."CONSTRAINTS"."TABLE_SCHEMA" ASC,
"INFORMATION_SCHEMA"."CONSTRAINTS"."CONSTRAINT_NAME" ASC,
"INFORMATION_SCHEMA"."CONSTRAINTS"."COLUMN_LIST" ASC
Also, could you provide me with the DDL of the table whose primary key is
not discovered? I cannot reproduce this issue with:
create table test ("Aa" int, "BB" int, "cc" int, primary key ("Aa",
"BB", "cc"));select * from information_schema.constraints where
lower(table_name) = 'test';
Just to be sure, are you using the latest jOOQ and H2 versions?
Cheers
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/groups/opt_out.