Search code examples
jpadb2eclipselinkclobdatabase-table

Supporting table structure changes in JPA/Eclipselink


I'm fairly new to JPA/Eclipselink and facing a problem which is in 2 parts - First - I needed to add CLOB field my existing table. I made the required change to persistence classes and it worked with MySQL as database without changing the below property:

<property name="eclipselink.ddl-generation" value="create-tables"/>

However on a DB2 database it does not work that way and had to change it to :

<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>

I realized that this is not going to work on the production environment running DB2 and I'm not sure whether there is any support within JPA/Eclipselink to support creation of the column without deleting the rest of the data.

Second - A CLOB or LOB field is not treated the same way on a DB2 as it is on MySQL. Althought it generated the requisite SQL script for the DB2 database when I deployed my application it looks like it wasn't enough (DB2 requires more than just a field declaration for a CLOB column - it seems ROWID, tablespace and a few more things are needed). Does JPA support this? If there isn't can I provide additional actions through JPA post deployment for running a script?

Any help with the above would be awesome.


Solution

  • If you add a field to your model, create-tables should NOT work as the table will already exist. drop-and-create-tables or create-or-extend-tables is necessary when making additive changes to your model. See here for the different EclipseLink ddl options. DDL though is generally frowned upon in production - you will want to create your own scripts to use to customize it for your DB use cases separately from the JPA model.