I am using the R2DBC (io.asyncer:r2dbc-mysql:1.1.3) + jOOQ (3.19.8) + MySQL (8.4.0) stack and I am having trouble setting a DDL with a default boolean value (although the issue might not be limited to just the default value).
Here is my DDL:
CREATE TABLE entity
(
id INT NOT NULL AUTO_INCREMENT,
deleted_tinyint tinyint(1) NOT NULL DEFAULT false,
deleted_bit bit(1) NOT NULL DEFAULT 0,
CONSTRAINT pk_entity PRIMARY KEY (id)
);
INSERT INTO test_schema.entity (deleted_tinyint, deleted_bit)
VALUES (DEFAULT, DEFAULT);
When I execute the query using JDBC…
private DSLContext ctx;
@Before
public void setup() {
Connection connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3310/test_schema",
"test",
"test"
);
ctx = DSL.using(connection, SQLDialect.MYSQL);
}
@Test
public void test() {
var fetched = ctx
.selectFrom(ENTITY)
.fetchOne();
log.info("{}", fetched);
}
…I get the following result:
+----+---------------+-----------+
| id | deleted_tinyint | deleted_bit |
+----+---------------+-----------+
| 1 | 0 | false |
+----+---------------+-----------+
However, when I execute the same query using R2DBC…
private DSLContext ctx;
@Before
public void setup() {
ConnectionFactory connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions
.parse("r2dbc:mysql://localhost:3310/test_schema")
.mutate()
.option(ConnectionFactoryOptions.USER, "test")
.option(ConnectionFactoryOptions.PASSWORD, "test")
.build()
);
ctx = DSL.using(connectionFactory);
}
@Test
public void test() {
var fetched = Flux.from(ctx.selectFrom(ENTITY))
.log()
.blockFirst();
}
… I get the following result:
+----+---------------+-----------+
| id | deleted_tinyint | deleted_bit |
+----+---------------+-----------+
| 1 | 0 | {null} |
+----+---------------+-----------+
For some reason, the column with type bit(1)
is not being read in the R2DBC query. This type is preferred for representing Boolean
values when working with MySQL.
I have also verified that the query being generated by jOOQ and executed by R2DBC is correct. If I take that same query and execute it using a MySQL client (e.g. MySQL Workbench), the result set includes the correct value for the deleted_bit
column.
I have found a workaround using forcedTypes + tinyint(1)
, but it seems strange that the standard approach does not work.
I have also prepared a repository to reproduce the error: https://github.com/yirelav/jOOQ-r2dbc-example-bug-repo (I tried to make a clear readme.md there)
Can anyone help me understand why this is happening and how I can fix it? Thank you in advance.
Valeriy Stavyanko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.