Spring Boot 和 PostgreSQL 中的更新和删除不是批量的

发布于 2025-01-10 02:12:55 字数 936 浏览 1 评论 0原文

我正在尝试让我的 Spring boot 应用程序使用批处理模式来创建更新和删除操作。 我已通过以下文章成功完成创建操作:

  1. https:// vladmihalcea.com/postgresql-multi-row-insert-rewritebatchedinserts-property/
  2. https://www.baeldung.com/jpa-hibernate-batch-insert-update< /a>

在我的应用程序级别,在代理数据源的帮助下,我可以看到批处理适用于我的所有操作,如下所示:

[-exec-6] SLF4JQueryLoggingListener:20 - {"name":"Batch-Insert-Logger", "connection":33, "time":9, "success":true, "type":"Prepared", "batch":true, "querySize":1, "batchSize":5, "query":["

在 PostgreSQL 级别,我可以看到配置后插入工作这我的数据库连接中的 reWriteBatchedInserts=true 。 我用实际的 PostgreSQL 日志验证了它。

但是,对于更新和删除操作,我仍然可以在日志中看到它没有在 PostgreSQL 级别进行批处理。 为了完成此任务,我需要做任何额外的配置吗?

先感谢您。

I'm trying to get my Spring boot application to work with batching mode for the create update and delete operations.
I have succeeded to do the creation operation with the following articles:

  1. https://vladmihalcea.com/postgresql-multi-row-insert-rewritebatchedinserts-property/
  2. https://www.baeldung.com/jpa-hibernate-batch-insert-update

At my application level, with the help of the proxy data source, I could see that the batching is working for all my operations, it looks like this:

[-exec-6] SLF4JQueryLoggingListener:20 - {"name":"Batch-Insert-Logger", "connection":33, "time":9, "success":true, "type":"Prepared", "batch":true, "querySize":1, "batchSize":5, "query":["

At the PostgreSQL level, I could see that the insertion works after I configured the reWriteBatchedInserts=true in my DB connection.
I verified it with the actual PostgreSQL logs.

However, for the update and delete operations, I can still see in the logs that it is not batched in the PostgreSQL level.
Is there any additional configuration that I need to do in order to get this done?

Thank you in advance.

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

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

发布评论

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

评论(1

丢了幸福的猪 2025-01-17 02:12:55

当我们想要使用批处理进行插入/更新时,我们应该了解主键生成策略。如果我们的实体使用 GenerationType.IDENTITY 标识符生成器,​​Hibernate 将默默地禁用批量插入/更新。

请改用序列...

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;

来源:Baeldung

When we want to use batching for inserts/updates, we should be aware of the primary key generation strategy. If our entities use GenerationType.IDENTITY identifier generator, Hibernate will silently disable batch inserts/updates.

Please use sequence instead...

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;

Source: Baeldung

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