how shall I define sequences in my project (which

2019-08-23 15:01发布

We have a java project that uses Hibernate as the OR Mapper. We need the project to work with both Oracle and Mysql. because some customers don't want to install Oracle. we have added @sequenceGenerator annotation on entities to have sequence. but the project can not connect to Mysql DBMS with these annotations. Is there any way that we can have sequences in both mysql and Oracle mode, without any changes?

2条回答
smile是对你的礼貌
2楼-- · 2019-08-23 15:09

in accordance to my knowledge it is not possible because

MySQL support AUTO_INCREMENT and Oracle support SEQUENCE

and there are many other factors to consider like data types and indexes

As Oracle is an ORDBMS where as mysql is DBMS it is lack of many features present in MySQL

SOLUTION

i think we can do this with separate databases for each of them

[ As we have many free tools to convert the data from Oracle to MySQL we can use them. Even some of them are not free but we can covert the structure usnig them link1 link2]

database migration needs a full understanding of the data types,indexes,column and table options,etc of both source and destination databases

or

you can use PostgreSQl which also supports SEQUENCES and it is also a GPL

查看更多
做自己的国王
3楼-- · 2019-08-23 15:27

Most portable way is to use TableGenerator. It is portable because no database provider specific constructs are used. Last generated value is stored to the database table, and value is retrieved and incremented via SQL queries.

Usage is also covered in Hibernate documentation.

查看更多
登录 后发表回答