Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL dialect converts all byte properties to boolean #589

Closed
hurahurat opened this issue Apr 23, 2021 · 3 comments
Closed

MySQL dialect converts all byte properties to boolean #589

hurahurat opened this issue Apr 23, 2021 · 3 comments
Labels
type: bug A general bug

Comments

@hurahurat
Copy link

I found that spring-data-r2dbc can read tinyint field as Byte type but I got 0 or 1 for tinyint fields in mysql/maridb database when inserting data.
It seems like byte field is converted to Boolean because of ByteToBooleanConverter in MySqlDialect class.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 23, 2021
@mp911de
Copy link
Member

mp911de commented Apr 26, 2021

ByteToBooleanConverter converts byte to boolean values when reading data from the database.

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal sample that reproduces the problem.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Apr 26, 2021
@hurahurat
Copy link
Author

Thank you for your response. Please look at this minimal sample.
demo.zip

These are scripts to create a sample database and table

CREATE DATABASE IF NOT EXISTS `test-db` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
USE `test-db`;

CREATE TABLE IF NOT EXISTS `user` (
  `user_id` int(11) NOT NULL AUTO_INCREMENT,
  `state` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

When hitting "/user/add" I got the response with a state value is 3 but the actual value saved in the database is 1.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Apr 26, 2021
@mp911de mp911de added type: bug A general bug and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels May 19, 2021
@mp911de mp911de changed the title Can not mapping between byte type to tinyint in mysql/mariadb MySQL dialect converts all byte properties to boolean May 19, 2021
mp911de added a commit that referenced this issue May 19, 2021
…iaDB.

ByteToBooleanConverter is now marked as reading converter and we've added a writing converter with BooleanToByteConverter to ensure proper conversion. Previously, all byte values were converted to boolean resulting in data precision loss.

Closes #589
mp911de added a commit that referenced this issue May 19, 2021
…iaDB.

ByteToBooleanConverter is now marked as reading converter and we've added a writing converter with BooleanToByteConverter to ensure proper conversion. Previously, all byte values were converted to boolean resulting in data precision loss.

Closes #589
@mp911de mp911de added this to the 1.2.10 (2020.0.10) milestone May 19, 2021
@mp911de
Copy link
Member

mp911de commented May 19, 2021

Thanks for the report and the example. The ByteToBooleanConverter in MySQL dialect, which is also used for MariaDB, converts all byte properties to boolean. The converter should actually be used only for reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants