Hibernate Panache extension do not support switching between mutliple datasources #42391
Replies: 2 comments 4 replies
-
/cc @FroMage (panache), @gsmet (hibernate-orm), @loicmathieu (panache), @yrodiere (hibernate-orm) |
Beta Was this translation helpful? Give feedback.
-
Fair warning: you'll regret this the very first time you face an Oracle-specific bug. This is a bad idea, you've been warned, now I'll shut up about this :)
To be fair what's mentioned in your link is exactly the limitation you're encountering:
You can use Panache with multiple persistence units, and even multiple datasources, it's just that each persistence unit must have its own entities. And yes, this is a known limitation. I don't know if there's an issue for it though, maybe @FroMage would know. In theory the limitation could be removed, but only in repository mode; active records most likely cannot handle this.
If:
... in that case yes, I think there is a workaround. IIRC, the application gets rebuilt by Quarkus for tests, dev, and prod, allowing you to update build-time settings such as So you just don't need multiple persistence units, and a simpler solution would be this: quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.datasource."pg".db-kind=postgres
quarkus.datasource."pg".jdbc.url=jdbc:postgresql:///your_database
quarkus.datasource."oracle".db-kind=oracle
quarkus.datasource."oracle".jdbc.url=jdbc:oracle:///your_database
%test,dev.quarkus.hibernate-orm.datasource=pg
%test,dev.quarkus.datasource."oracle".active=false
%prod.quarkus.hibernate-orm.datasource=oracle
%prod.quarkus.datasource."pg".active=false You won't find that in the documentation though (at least I hope so), because as stated above, it's a bad practice. |
Beta Was this translation helpful? Give feedback.
-
Task: switch database provider depending on environment. postgresql for test and dev, oracle for prod.
Expectation: hibernate is a great orm tool that also provides abstraction from the database engine, so we expected some simple setting to switch db-kind and connection url via environment variables and everything would work out of the box.
Result: mission seems impossible due to so many obstacles starting with db-kind and many other datasource and hibernate config properties being locked on build-time and thus not available to runtime config.
Anyway, we have followed a guide to configure multiple data sources and activate only one them:
but that is not supported by panache extension despite being mentioned in its documentation as well https://quarkus.io/guides/hibernate-orm-panache#multiple-persistence-units
the problem is that panache requires an entity to be linked to a single persistent unit and we have two of them even though only one is active at a time
panache extension provides a great support to manage entity related operations so we would like to keep it and not switching back to basic hibernate functionality.
any workarounds to overcome this issue?
Beta Was this translation helpful? Give feedback.
All reactions