java - 在使用存储库模式时,如何使用 Hibernate 响应式(Reactive) Panache 库在 Quarkus 3.0.0.RC2 中响应式(Reactive)列出具有不同参数的实体?

标签 java reactive-programming quarkus quarkus-panache quarkus-reactive

我正在开发一个项目,使用 Quarkus 3.0.0.CR2 和 Hibernate Reactive Panache 作为响应式(Reactive)应用程序的 ORM。该应用程序使用 API resource 从主人那里检索动物对 service 进行 5 次响应式(Reactive)调用,转发到 database repository implementation .

但是,当重复运行 unit test 时或者对“http://localhost:8080/zoo/animals/Melani”进行 curl 调用,我随机遇到两个不同的错误:

  • org.hibernate.HibernateException: java.util.concurrent.CompletionException: java.lang.IllegalStateException: Session/EntityManager 已关闭
  • org.hibernate.HibernateException:java.util.concurrent.CompletionException:java.util.NoSuchElementException

有人可以帮助我理解为什么会遇到这些错误并提出解决方案吗?

以下是 Github 上示例项目的链接,该项目演示了该错误:https://github.com/Lukec1/quarkus-3.0.0.CR2-sample

预先感谢您的帮助。

最佳答案

根据设计,hibernate reactive 无法在并行线程上共享 session ,该 session 会阻塞与 Uni 或 Mutiny 的使用。

The problem is that Hibernate Reactive needs operations on the database to happen in a predictable order to avoid errors when managing entities. So, you cannot share the same session among different threads or uni streams.

We don't have a solution for this at the moment, and chaining the uni is the only way to be sure that everything will work as expected.

这是real source

关于java - 在使用存储库模式时,如何使用 Hibernate 响应式(Reactive) Panache 库在 Quarkus 3.0.0.RC2 中响应式(Reactive)列出具有不同参数的实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76072695/

相关文章:

java - 自动为枚举添加类似 Java 枚举的功能

java - 如何查询实体并将计数聚合到值对象上

macos - Quartz Composter —重新创建Audioskop(根据音频输入调整视频时间)

firebase-authentication - Quarkus 和 Firebase 身份验证

java - 无法将值从 Bash 脚本传递到 Java 程序

java - Memcached 与 Hibernate 的集成

javascript - 为顺序提取选择适当的运算符

android - 如何让这段用 RxKotlin 编写的代码块更干净,避免阻塞线程?

quarkus - 如何在 Quarkus 中设置日志记录级别?

mariadb - 如何在 Quarkus 测试中使用 MariaDB devservices?