Hi Sander, Unfortunately, lacking meaningful regression tests, this functionality is very limited in version 1.6.1. Right now, it works only if you have
1. an Integer PK 2. a String literal 3. a String description And no other columns. That's pretty poor. These fixes will be given a very high priority for the next release. Until then, I discourage using that feature. Regards Lukas 2011/6/22 Lukas Eder <[email protected]>: > Hi Sander, > > 1. Primary key of type VARCHAR > That's probably a regression from some previous version. I don't have > integration tests for primary key types other than NUMBER/INT. This > will be fixed in 1.6.2 > https://sourceforge.net/apps/trac/jooq/ticket/654 > > 2. Adding an INT primary key > That might be another bug. I'll have to investigate that. I suspect it > will have to do with adding the INT primary key as the last column. > > These master data tables do need more test cases > Thanks for reporting > > Lukas > > 2011/6/22 Sander Plas <[email protected]>: >> I'm trying to use master data tables in jOOQ 1.6.1 with PostgreSQL. I >> know i can use real ENUMs, but i prefer a table because some of the >> value lists are quite long and ENUMs are a bit hard to maintain in >> PostgreSQL - you have to drop & re-create them every time you want to >> add a value. >> >> My master data config: >> ---------------------------------------------------------------------------------------------------------------------------------------------------------- >> generator.generate.master-data-tables=unit >> generator.generate.master-data-table-literal.unit=name >> generator.generate.master-data-table-description.unit=description >> ---------------------------------------------------------------------------------------------------------------------------------------------------------- >> >> When i use a master table that has a varchar as primary key (it's the >> actual "literal" field), i get: >> ---------------------------------------------------------------------------------------------------------------------------------------------------------- >> ERROR - DefaultGenerator - Exception while generating master >> data table unit >> java.lang.RuntimeException: org.postgresql.util.PSQLException: Bad >> value for type int : euro >> at org.jooq.impl.CursorImpl$CursorIterator.next(CursorImpl.java:164) >> at org.jooq.impl.CursorImpl$CursorIterator.next(CursorImpl.java:127) >> at org.jooq.impl.CursorImpl.fetch(CursorImpl.java:119) >> at >> org.jooq.impl.AbstractResultProviderQuery.execute(AbstractResultProviderQuery.java: >> 74) >> at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:103) >> at >> org.jooq.impl.AbstractResultProviderQuery.fetch(AbstractResultProviderQuery.java: >> 96) >> at >> org.jooq.impl.AbstractDelegatingResultProviderQuery.fetch(AbstractDelegatingResultProviderQuery.java: >> 98) >> at >> org.jooq.util.DefaultMasterDataTableDefinition.getData(DefaultMasterDataTableDefinition.java: >> 92) >> at org.jooq.util.DefaultGenerator.generate(DefaultGenerator.java:342) >> at org.jooq.util.GenerationTool.main(GenerationTool.java:142) >> at org.jooq.util.GenerationTool.main(GenerationTool.java:101) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java: >> 39) >> at >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: >> 25) >> at java.lang.reflect.Method.invoke(Method.java:597) >> at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:283) >> at java.lang.Thread.run(Thread.java:662) >> Caused by: org.postgresql.util.PSQLException: Bad value for type int : >> euro >> at >> org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.java: >> 2759) >> at >> org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java: >> 2003) >> at >> org.jooq.impl.FieldTypeHelper.getFromResultSet(FieldTypeHelper.java: >> 417) >> at >> org.jooq.impl.FieldTypeHelper.getFromResultSet(FieldTypeHelper.java: >> 366) >> at org.jooq.impl.CursorImpl$CursorIterator.setValue(CursorImpl.java: >> 201) >> at org.jooq.impl.CursorImpl$CursorIterator.fetch(CursorImpl.java:186) >> at org.jooq.impl.CursorImpl$CursorIterator.next(CursorImpl.java:162) >> ... 16 more >> ---------------------------------------------------------------------------------------------------------------------------------------------------------- >> >> When i add a separate integer column to the table and make that the >> primary key, code generation completes without errors, but the >> resulting code doesn't work: >> >> ---------------------------------------------------------------------------------------------------------------------------------------------------------- >> public enum Unit implements MasterDataType<Integer> { >> >> /** >> * uur-description >> */ >> uur(4, "uur", "uur-description"), >> >> <...> >> >> private final String name; >> private final String description; >> private final Integer id; >> >> private Unit(String name, String description, Integer id) { >> this.name = name; >> this.description = description; >> this.id = id; >> } >> ---------------------------------------------------------------------------------------------------------------------------------------------------------- >> error: constructor Unit in enum nl.seeas.bite.db.enums.Unit cannot be >> applied to given types; >> required: java.lang.String,java.lang.String,java.lang.Integer >> found: int,java.lang.String,java.lang.String >> reason: actual argument int cannot be converted to java.lang.String >> by method invocation conversion >> ---------------------------------------------------------------------------------------------------------------------------------------------------------- >> >> Am i doing something wrong or is this broken in jOOQ-codegen? >
