插入不要返回多个生成的ID

发布于 2025-01-24 11:50:35 字数 676 浏览 3 评论 0原文

我目前正在尝试实现插入(请参阅 https://www.jooq.org/doc/latest/manual/sql-building/sql-statement/insert-statement/insert-statement/insert-ertert-returning/ )。不同之处在于,我不直接使用值,而是带有记录的集合。

在日志中,我看到执行了2个插入物,但是在记录结果中总是只有1个结果。测试与H2。

FooRecord foo1;
FooRecord foo2;

   final Result<?> result =
            create.insertInto( FOO)
                  .set( foo1 )
                  .set( foo2 )
                  .returningResult( FOO.ID )
                  .fetch();

我在做什么错?

I am currently trying to implement an insert (see https://www.jooq.org/doc/latest/manual/sql-building/sql-statements/insert-statement/insert-returning/). The difference is that I don't use values ​​directly, but the set with record.

In the log I see that 2 inserts are executed, but in the Records Result there is always only 1 result. Test is with H2.

FooRecord foo1;
FooRecord foo2;

   final Result<?> result =
            create.insertInto( FOO)
                  .set( foo1 )
                  .set( foo2 )
                  .returningResult( FOO.ID )
                  .fetch();

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

む无字情书 2025-01-31 11:50:35

检查 插入.. set文档,列出了调用newRecord()的调用。您必须在记录之间放置标记,以清楚区分它们:

final Result<?> result =
create.insertInto( FOO)
      .set( foo1 )
      .newRecord() // This call is necessary
      .set( foo2 )
      .returningResult( FOO.ID )
      .fetch();

否则,连续的set()调用只是互相覆盖。

Check the example of the INSERT .. SET documentation, which lists a call to newRecord(). You have to place a marker between your records to clearly distinguish between them:

final Result<?> result =
create.insertInto( FOO)
      .set( foo1 )
      .newRecord() // This call is necessary
      .set( foo2 )
      .returningResult( FOO.ID )
      .fetch();

Otherwise, the consecutive set() calls just override one another.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文