Why jooq is not returning when mysql table has a unique index?

141 views Asked by At

Mysql table is like

CREATE TABLE `User` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `telphone` varchar(32) NOT NULL,
  `name` varchar(64) NOT NULL DEFAULT '',
  `password` varchar(64) NOT NULL DEFAULT '',
  `balance` int(11) NOT NULL DEFAULT '0',
  `user_type` int(2) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `phone_index` (`telphone`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8;

And the code I write is :

@Service
public class CommonDao {
    @Resource
    private DSLContext jooqContext;

    public <R extends Record> R insertAndGet(Table<R> table, R r, Field<?>... f) {
        return jooqContext.insertInto(table).set(r).returning(f).fetchOne();
    }
}

It always return null when I use the insert and get, and the data actually insert into the database. But When I delete the unique key in the mysql, It works fine.

0

There are 0 answers