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

【请求】SQL server 插入非自增主键问题 #905

Open
WangJincheng4869 opened this issue Feb 6, 2024 · 1 comment
Open

【请求】SQL server 插入非自增主键问题 #905

WangJincheng4869 opened this issue Feb 6, 2024 · 1 comment

Comments

@WangJincheng4869
Copy link

内置的 SQL server 目前是直接跳过主键的插入,这样是无法插入非自增主键的(雪花算法主键)。

我尝试进行了修改,让其可以插入主键,成功了但是有一个问题。

插入成功后会将实体类中的主键清空,原始代码中是下面这行处理的主键,请问是在哪里设置的主键值,我能否添加判断不让其覆盖掉我实体类中的主键值,因为这个主键值对我来说可能有用,因为会加入 redis 或 mq 中会使用到。

// 反射把 MappedStatement 中的设置主键名
EntityHelper.setKeyProperties(EntityHelper.getPKColumns(entityClass), ms);

MySQL 是没有问题的,依旧是我设置的主键。

@abel533
Copy link
Owner

abel533 commented Feb 7, 2024

针对自增和非自增选择不同的insert方法实现,别共用。

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

No branches or pull requests

2 participants