vertx-jooq
vertx-jooq copied to clipboard
PostgreSQL Name Case Issues When Generating Using JPADatabase
I am generating jOOQ DAOs using JPADatabase in my example project
For some reason, when I try to create a new row/record using the DAO's insertReturningPrimary
method, I get the following error:
09:00:20.253 [vert.x-eventloop-thread-1] ERROR com.redhat.runtimes.services.TodosServiceImpl - Column ID does not exist
java.util.NoSuchElementException: Column ID does not exist
at io.vertx.sqlclient.Row.getValue(Row.java:65) ~[vertx-sql-client-4.1.4.jar:4.1.4]
at io.github.jklingsporn.vertx.jooq.shared.reactive.AbstractReactiveVertxDAO.lambda$generatePostgresKeyConverter$1(AbstractReactiveVertxDAO.java:49) ~[vertx-jooq-shared-reactive-6.3.0.jar:?]
I have tried tweaking the Configuration
to change how names/fields/schemas are rendered with respect to letter case, but it's pretty hit and miss (Mostly miss) so far. In my database, the column is id
(lower case) and when jOOQ attempts to fetch the column is it asking for ID
(upper case) at io.vertx.sqlclient.Row.getValue(Row.java:65)
at which point it fails.
Any advice? If you would like to run the example project:
- Clone the repository
- Switch to the
Issue-7-_-Debug_createTodo_operation
branch:git checkout Issue-7-_-Debug_createTodo_operation
- Compile the code
mvn clean compile
- Start the PostgreSQL Container (this uses a generated DDL script from the models module, so you MUST compile first) using
docker-compose up
in the root of the project - Run the Vert.x application using
mvn -pl modules/api clean compile vertx:run
- Access the Swagger UI
- Attempt to create a new Todo item using Swagger UI
Hmmm... Some more information... The actual insertion of the data in the table is successful, it is just the returning of the ID field which causes a problem.
This seems to be unrelated to the insertReturningPrimary
and is instead related to the generated RowMapper
which looks like:
public class RowMappers {
private RowMappers(){}
public static Function<Row,com.redhat.runtimes.data.access.tables.pojos.Todos> getTodosMapper() {
return row -> {
com.redhat.runtimes.data.access.tables.pojos.Todos pojo = new com.redhat.runtimes.data.access.tables.pojos.Todos();
pojo.setId(row.getUUID("ID"));
pojo.setAuthor(row.getString("AUTHOR"));
pojo.setComplete(row.getBoolean("COMPLETE"));
pojo.setCreated(row.getLocalDateTime("CREATED"));
pojo.setDescription(row.getString("DESCRIPTION"));
pojo.setDuedate(row.getLocalDateTime("DUEDATE"));
pojo.setTitle(row.getString("TITLE"));
return pojo;
};
}
public static Function<Row,com.redhat.runtimes.data.access.tables.pojos.Users> getUsersMapper() {
return row -> {
com.redhat.runtimes.data.access.tables.pojos.Users pojo = new com.redhat.runtimes.data.access.tables.pojos.Users();
pojo.setId(row.getUUID("ID"));
pojo.setFamilyname(row.getString("FAMILYNAME"));
pojo.setGivenname(row.getString("GIVENNAME"));
pojo.setName(row.getString("NAME"));
pojo.setPreferredusername(row.getString("PREFERREDUSERNAME"));
return pojo;
};
}
}
The calls to row.getXXX()
are using uppercase field names and those are not matching the field names from the PostgreSQL Reactive client which are in lower case.