1

I'd like to deploy my application on multiple servers. Those servers have different database-managers. (one is Oracle, the other is Postgres in this case).

These require different persistence unit configurations, because Hibernate needs the dialect defined for Oracle, but then the Postgres db won't work. Sadly, by not configuring the dialect in the persistence.xml, Hibernate is unable to auto-detect the Oracle dialect.

Is there a way to define the persistence unit configuration for the environment?

László Stahorszki
  • 1,102
  • 7
  • 23
  • See: https://stackoverflow.com/a/1990914/2849346 => "Data Source" via JNDI. – MWiesner May 18 '19 at 16:19
  • I know how to get a datasource via JNDI. I need the Persistence Unit itself. A rough example: something like getting the persistence.xml from JNDI would be a good solution – László Stahorszki May 18 '19 at 20:05
  • Have you tried the `LocalContainerEntityManagerFactoryBean.persistenceXmlLocation` property? – crizzis May 19 '19 at 12:34
  • Correct me if I'm wrong, but this bean is only available in Spring. I'm working in java enterprise edition as the tag suggests – László Stahorszki May 19 '19 at 12:45
  • You can define multiple persistence units in one `persistence.xml`, and choose which one to launch when calling `Persistence.createEntityManagerFactory` – coladict May 20 '19 at 07:39
  • I'd like a more general solution, where the environment knows the database configuration. Similar, to how JNDI Datasources work, but a bit more abstract – László Stahorszki May 21 '19 at 11:16
  • Possible duplicate of [Is there a means by which to configure Hibernate Dialect Based on jta-data-source?](https://stackoverflow.com/questions/14962519/is-there-a-means-by-which-to-configure-hibernate-dialect-based-on-jta-data-sourc) – Buurman Jun 25 '19 at 08:12
  • see my edit, sadly this solution doesn't work – László Stahorszki Jun 25 '19 at 10:14

0 Answers0