1

I'd like to make my application powered by Spring Data JPA transparently compatible with both MSSQL and Oracle. My application contains a few pieces of native SQL queries and ideally I'd like to organize this as the usual common Spring Data repository XXXRepository with vendor-independent JPQL queries and a couple of extensions as the vendor-specific Spring Data repositories like XXXOracleRepository/XXXMSSQLRepository with vendor-specific native queries.

Is it possible ?

Roman Sinyakov
  • 559
  • 1
  • 6
  • 24
  • put database specific stuff in their own "orm.xml" file and point the persistence unit at the appropriate orm.xml for the datastore ? That's how you would do it with standard JPA – Neil Stockton Sep 01 '16 at 14:53
  • Thanks, Neil, it seems the way to go: one needs 1) to move all the native queries from the source code into the vendor-specific `orm.xml` and 2) to make spring use `AbstractRoutingDataSource` according to http://stackoverflow.com/a/12630799/999367. The question I still have is how to configure JPA to have 1 persistence unit and separate `orm.xml` per database vendor. Whether to include the corresponding `mapping-file` section is not configurable in `persistence.xml`. It seems impossible which means we have to have multiple persistence units and a sort of `AbsractEntityManagerFactory`. – Roman Sinyakov Sep 12 '16 at 12:35

0 Answers0