【问题标题】:Connect Panache to multiple Datasources将 Panache 连接到多个数据源
【发布时间】:2021-11-22 14:34:28
【问题描述】:
有没有办法将 Panache 与多个数据源一起使用?
当我使用另一个数据库时,我想使用 Panache 而不是创建本机查询。
目前,我只能在默认数据源中使用 Panache,当我需要在另一个数据库中执行某些查询时,需要使用 @PersistenceUnit 和存储库中的 EntityManager,从而创建一个原生查询。
【问题讨论】:
标签:
java
quarkus
multiple-databases
quarkus-panache
【解决方案1】:
你可以,它记录在here。
在您的实体上使用正确的@PersistenceUnit,Hibernate with Panache 将在封面下使用正确的EntityManager。在 Panache 方面没有什么特别的用途。
您甚至可以使用MyEntity.getEntityManager() 或myRepository.getEntityManager() 访问正确的EntityManager,因为Panache 将使用来自@PersistenceUnit 的信息来选择它。