sql-server - r2dbc-mssql generatedKey 返回类型 numeric
问题描述
示例堆栈:Spring Data R2dbc 1.0.0.RELEASE、R2dbc Mssql 0.8,完整代码在这里。
初始化脚本:
use tempdb;
IF OBJECT_ID(N'dbo.posts', N'U') IS NULL
BEGIN
CREATE TABLE posts (
id BIGINT NOT NULL IDENTITY(1,1) PRIMARY KEY,
title VARCHAR (50) NOT NULL,
content VARCHAR (50) NOT NULL,
createdAt DATETIME,
updatedAt DATETIME
)
END;
保存数据并从中获取生成的密钥时DataInitializer
。
@Component
@Slf4j
class DataInitializer {
private final DatabaseClient databaseClient;
public DataInitializer(DatabaseClient databaseClient) {
this.databaseClient = databaseClient;
}
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
log.info("start data initialization...");
this.databaseClient.delete().from("posts")
.then().
and(
this.databaseClient.insert()
.into("posts")
//.nullValue("id", Integer.class)
.value("title", "First post title")
.value("content", "Content of my first post")
.map((r, m) -> r.get( 0, BigDecimal.class)).all()
.log()
)
.thenMany(
this.databaseClient.select()
.from("posts")
.orderBy(Sort.by(desc("id")))
.as(Post.class)
.fetch()
.all()
.log()
)
.subscribe(null, null, () -> log.info("initialization is done..."));
}
}
如果我在行中使用Integer
orLong
而不是,它将引发错误,指示无法解码类型 [java.lang.Long] 的值,名称 [GENERATED_KEYS] 服务器类型 [numeric],它不是架构脚本中定义的,我必须使用 a才能使其工作。BigDecimal
.map((r, m) -> r.get( 0, BigDecimal.class)).all()
bigint
BigDecimal
解决方案
推荐阅读
- regex - 在 RegEx 中的最后一个斜杠之后获取值并忽略类别 slug
- php - 从 woocommerce 产品 url 获取页面参数
- java - 如何将我的变量保持为私有并仍然获得所需的输出?
- python - 为什么更新字典会从我的嵌套数组中删除其余的字典?
- javascript - 我是否需要 XMLHttpRequest 才能使用 JavaScript 更改 JSON 文件值?
- php - PHP XML 不使用 SimpleXml 解析
- yaml - YAML 中的多个引用在第 43 行重复映射键错误
- javascript - 如何在笔记应用程序中获得一致的 javascript 语法突出显示?
- php - 我是新手,需要帮助 xD 我在 sql 中有错误,但我不知道在哪里。拉拉维尔 7
- oracle-apex - 带有多选功能的弹出式 LOV