Enums not generated/mapped using simple programmatic code generation

23 views
Skip to first unread message

jklingsporn

unread,
Jun 16, 2017, 4:12:05 AM6/16/17
to jOOQ User Group
Hi,

I've figured out that when generating code using the programmatic configuration enums are not properly generated/mapped. Since I'm not sure if I'm doing it wrong, I post in this group rather than creating a github issue ^^ 
This is the code-generator:

public class Main {

public static void main(String[] args) {
Configuration configuration = createGeneratorConfig();
try {
GenerationTool.generate(configuration);
} catch (Exception e) {
e.printStackTrace();
}
}


private static Configuration createGeneratorConfig(){
Jdbc jdbcConfig = new Jdbc();
jdbcConfig.setDriver("com.mysql.jdbc.Driver");
jdbcConfig.setUrl("jdbc:mysql://127.0.0.1:3306/");
jdbcConfig.setUser("user");
jdbcConfig.setPassword("password");

Configuration configuration = new Configuration();
Database databaseConfig = new Database();
databaseConfig.setName(MySQLDatabase.class.getName());
databaseConfig.setInputSchema("test");
databaseConfig.setOutputSchemaToDefault(true);
databaseConfig.setIncludes("example");

Target targetConfig = new Target();
targetConfig.setPackageName("generated");
targetConfig.setDirectory("src/main/java");

Generate generateConfig = new Generate();
generateConfig.withInterfaces(true);

Strategy strategy = new Strategy();
strategy.setName(DefaultGeneratorStrategy.class.getName());

Generator generatorConfig = new Generator();
generatorConfig.setName(JavaGenerator.class.getName());
generatorConfig.setDatabase(databaseConfig);
generatorConfig.setTarget(targetConfig);
generatorConfig.setGenerate(generateConfig);
generatorConfig.setStrategy(strategy);
configuration.setGenerator(generatorConfig);

configuration.setJdbc(jdbcConfig);

return configuration;
}
}

This is how the table looks like:

CREATE TABLE `example` (
  `someId` int(11) NOT NULL AUTO_INCREMENT,
  `someEnum` enum('FOO','BAR','BAZ') DEFAULT NULL,
  PRIMARY KEY (`someId`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;


And finally this is the generated interface:

@Generated(
value = {
"http://www.jooq.org",
"jOOQ version:3.9.2"
},
comments = "This class is generated by jOOQ"
)
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
public interface IExample extends Serializable {

/**
* Setter for <code>example.someId</code>.
*/
public void setSomeid(Integer value);

/**
* Getter for <code>example.someId</code>.
*/
public Integer getSomeid();

/**
* Setter for <code>example.someEnum</code>.
*/
public void setSomeenum(String value);

/**
* Getter for <code>example.someEnum</code>.
*/
public String getSomeenum();

// -------------------------------------------------------------------------
// FROM and INTO
// -------------------------------------------------------------------------

/**
* Load data from another generated Record/POJO implementing the common interface IExample
*/
public void from(generated.tables.interfaces.IExample from);

/**
* Copy data into another generated Record/POJO implementing the common interface IExample
*/
public <E extends generated.tables.interfaces.IExample> E into(E into);
}

Obviously I've expected field someEnum to be an generated EnumType and not String. What am I doing wrong?
PS: generating code using the maven-generator works and I'm using jooq 3.9.2.

Lukas Eder

unread,
Jun 16, 2017, 4:31:31 AM6/16/17
to jooq...@googlegroups.com
Thank you very much for your report.

This looks like a bug. I've registered an issue for this:

A similar issue has been reported on Stack Overflow as well:

Can you confirm the enum type is generated, but it isn't linked to the generated tables?

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

jklingsporn

unread,
Jun 16, 2017, 4:40:42 AM6/16/17
to jOOQ User Group
It gets generated when I leave out

databaseConfig.setIncludes("example");

With the configuration above it does not.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.

Lukas Eder

unread,
Jul 11, 2017, 5:41:02 AM7/11/17
to jooq...@googlegroups.com
I'm sorry for the delay in this. There's recently been a similar issue posted to Stack Overflow:

In your case, I'm positive this is related to the <outputSchemaToDefault/> flag, which causes this problem both in MySQL and PostgreSQL.

A fix is on the way for jOOQ 3.10, 3.9.4, and 3.8.8:


Hope this helps,
Lukas

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