ktorm
ktorm copied to clipboard
i cant insert UUID into database
Database: mariadb
The code below throws an error:
db.batchInsert(PlayerKeys) {
for(playerKey in batchInsertList) {
item {
set(it.crateId, playerKey.crate.id)
set(it.amount, playerKey.amount)
set(it.uuid, playerKey.uuid)
}
}
}
Table object:
object PlayerKeys : Table<PlayerKey>("player_keys") {
val id = long("id").primaryKey().bindTo { it.id }
val uuid = uuid("uuid").bindTo { it.uuid }
val crateId = long("crate_id").references(Crates) { it.crate }
val amount = int("amount").bindTo { it.amount }
}
Error:
Data truncation: Incorrect uuid value: '\xAC\xED\x00\x05sr\x00\x0Ejava.util.UUID\xBC\x99\x03\xF7\x98m\x85/\x02\x00\x02J\x00\x0CleastSigBitsJ\x00\x0BmostSigBitsxp\x83...' for column `db`.`player_keys`.`uuid` at row 1
Table:
CREATE TABLE IF NOT EXISTS player_keys (
id BIGINT NOT NULL AUTO_INCREMENT,
uuid UUID NOT NULL,
crate_id BIGINT NOT NULL,
amount INT NOT NULL,
PRIMARY KEY (id)
);
Thank you for your feedback, I will fix this bug in the next version. You can use varchar as a workaround before the fix.
Upgrading to MariaDB Connector/J 3.1.0 can fix your problem. See https://mariadb.com/kb/en/mariadb-connector-j-3-1-0-release-notes/#uuid-object-support