F___
F___

Reputation: 139

Mysql query default value '' not equal java ""

I'm using Mybatis query database

mysql table structure

enter image description here

parent_id default is ''

insert value is

enter image description here

Mybatis get value seem error? , parent_id should be "" instead null value?

enter image description here

Upvotes: 0

Views: 154

Answers (1)

if your value in DB is empty string and in your Java object is int/Integer, MyBatis cannot cast the column. To solve this, you can either:

  • Modify your database to make parent_id default null
  • Modify your select query and change column parent_id to IF(parent_id = '', null, parent_id) as parent_id

Upvotes: 1

Related Questions