简体   繁体   中英

JPA/Hibernate - Sequence - migrating from Oracle to DB2

Would it be easy to migrate from Oracle to DB2 if I use below written Hibernate/JPA setup for my @Id attributes in domain classes?

@SequenceGenerator(name = "ExampleSeq", sequenceName = "EXAMPLE_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ExampleSeq")

Sequences are created for every table and prerequisite is to use them as a ID generator for every insertion. This is the script fragment for one table:

CREATE SEQUENCE "EXAMPLE"."EXAMPLE_SEQ" NOCYCLE NOCACHE START WITH 1 NOMAXVALUE;

Does DB2 supports sequences like that? I'm not sure.

Now I'm using Oracle in development and there's no worries. What are my options when it comes to migration from Development to some other kind of environment like Test or Production with DB2 as a persistence layer database?

Everything works pretty well with JPA/Hibernate abstraction and I'm sure that switching is manageable. There's only those sequences issue I mentioned that bothers me and I don't know how to deal with.

Need your help. Thanks.

Make a configuration parameter. Set it to Oracle or DB2. If you have to use one or more databases, then program for the variation around this configuration parameter. Postgresql has a column named serial that takes care of creating these for each table, if you so desire. You may be looking more about schema definition issues than Hibernate/JPA issues. Just use the same name in all the schema definitions. ROWNUM = 1 is an Oracle thing. Use limit = 1. You might have to watch for these kind-of issues too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM