Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA entity compatibility for both SQL Server and Oracle (auto-increment column issues)

I'm developing a Java EE JBoss service which will be deployed in two different environments: one using SQL Server as the database, and a different one which uses Oracle 10g.

My database schemas are very similar, except that the primary key columns are identity-auto-increment in SQL Server and generated using sequences in Oracle.

With JPA, is it possible to use a single set of entities with both DB's?

Thanks!

like image 971
Jon Onstott Avatar asked Mar 20 '26 19:03

Jon Onstott


1 Answers

Of course you can, but just specify the generated-value definition for the PK field in XML metadata rather than annotations. Use 2 different "orm.xml" files, so, for example, use "persistenceUnitOracle" for Oracle that references orm-oracle.xml, and "persistenceUnitSqlServer" for SQLServer that references orm-sqlserver.xml

like image 101
DataNucleus Avatar answered Mar 22 '26 14:03

DataNucleus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!