seata + mybatisplus + postgres, insert record id becomes null

gkn4icbw  于 22天前  发布在  其他
关注(0)|答案(7)|浏览(14)
  • [ x] I have searched the issues of this repository and believe that this is not a duplicate.

Ⅰ. Issue Description

用mapper插入新的用户信息的时候id 是null ,数据库是postgres, 我加了seata的@globaTransactional 之后就变成null 了, 没加这个注解是可以正常插入的。如果换成mysql 也能正常插入。 试过把posgres 的id 换成int 和bigint 都不行

Ⅵ. Environment:

  • JDK version(e.g. java -version ): Java 11
  • Seata client/server version: 1.7.0
  • Database version: postgres 16
  • OS(e.g. uname -a ): Mac
  • mybatis plus:3.4.0
  • Others:
cwdobuhd

cwdobuhd1#

Can you provide the table structure and a demo for replay

mutmk8jj

mutmk8jj2#

Can you provide the table structure and a demo for replay

users: table

  • columns
    id: bigint NN default nextval('users_id_seq'::regclass)
    . references
    sequence = users_id_seq
    name: varchar(128) default NULL::character varying
    -- Nickname
    pwd: varchar(124) default NULL::character varying
    -- Password
    head_img: varchar(524) default NULL::character varying
    -- Profile Picture
    slogan: varchar(524) default NULL::character varying
    -- User Signature
    sex: smallint default 1
    -- 0 for female, 1 for male
    points: integer default 0
    -- Points
    create_time: timestamp
    mail: varchar(64) default NULL::character varying
    -- Email
    secret: varchar(12) default NULL::character varying
    -- Salt, used for personal sensitive information processing
  • indices
    #1 : unique (id)
    #2 : unique (mail)
  • keys
    #1 : PK (id) (underlying index #1 )
    #2 : AK (mail) (underlying index #2 )
cotxawn7

cotxawn73#

Can you upload a demo or use a pseudo-code description,I want to see mapper.xml how to write and some config, so can to replay.

blpfk2vs

blpfk2vs4#

Can you upload a demo or use a pseudo-code description,I want to see mapper.xml how to write and some config, so can to replay.

You can reference to the code here

If I add the global transactional decorator at the register function, then what's on line 87 will log a null id

b4wnujal

b4wnujal5#

had readed your case, module user-service dependence exclude not ok, actual seata version is 1.1.0. after update, it will be work will.

so why seata 1.1 result difference between mysql and postgrel when return pk to object?

when happens insert, there will be generate undolog in seata, the process will get the pk, when finish read the resultSet , mysql cursor can move back, but postgrel cursor can't.

when mybatis fill pk to object, it will get pk too, so mysql cursor can continue to read, but postgrel already finish read cursor, so can't read.

current seata version fix the issue, when generate undolog, read the pk resultset, there will be cache for pk, so next operation will read the cache.

3z6pesqy

3z6pesqy6#

had readed your case, module user-service dependence exclude not ok, actual seata version is 1.1.0. after update, it will be work will.

so why seata 1.1 result difference between mysql and postgrel when return pk to object?

when happens insert, there will be generate undolog in seata, the process will get the pk, when finish read the resultSet , mysql cursor can move back, but postgrel cursor can't.

when mybatis fill pk to object, it will get pk too, so mysql cursor can continue to read, but postgrel already finish read cursor, so can't read.

current seata version fix the issue, when generate undolog, read the pk resultset, there will be cache for pk, so next operation will read the cache.

I specified the version of seats in the common package to 1.7.0 which matches the seata version that I am using. I am also assume that given 1.7.0 is later that 1.1. It should have contained the fix that is implemented right?

jv4diomz

jv4diomz7#

yeah, 1.7.0 contain the fix. currently, actual seata version is 1.1.0 in your user-service module, you can explicit add seata dependency to 1.7.0 in it, have a try.

相关问题