开发者

How to make a Hibernate application DB-independent?

开发者 https://www.devze.com 2023-01-30 11:51 出处:网络
We are currently using Oracle 10g internally for our project, and that is not likely to change, but eventually we are going to offer this application to other customers and we need to be able to propo

We are currently using Oracle 10g internally for our project, and that is not likely to change, but eventually we are going to offer this application to other customers and we need to be able to propose an alternative free DB.

So what is the best way to make a Hibernate per开发者_运维问答sistence layer independent of the underlying RDBMS used ? Ideally I would like to be able to just change the JDBC URL and the dialect used, and so switch between (at least) Oracle 10g and MySQL or PostgreSQL.

The main problem comes from the ID generation strategy. We are currently using Sequence based generators for our ID's, with one sequence per table. The obvious move seems to switch to the "native" strategy. But then will it be one unique sequence for all the tables ? What will happen to the existing data in our production system running on Oracle ? How to migrate ? What are the traps ?

Any other things to be aware when switching from one RDBMS/dialect to another ?


I think hilo ID generator is portable across all databases. But if you chose 'native', then we'll have some challenge migrating the database data. Its better to start from scratch in the new database, initalizing initial scheme data by creating objects and using Hibernate to save them. That means no more initializing schema by restoring from one of the database dump/backups and deleting transaction rows :)

0

精彩评论

暂无评论...
验证码 换一张
取 消