Search code examples
javaopenjpa

What does OpenJPA do with a db schema when entities change?


I have one entity which is mapped to a db schema currently. I am going to change this into two entities and was wondering how OpenJPA would handle this? My main concern is regarding the old data currently in the db..

The change is the following. Currently I have a Set of Strings (as an ElementCollection) in the original entities, but I would like to change this to a Map of a String to an Entity (In a OneToMany relation). This works so far on my test system and leads to two more columns in one table. Would OpenJPA be intelligent enough to just add those column? And if so could I set default values for these?


Solution

  • The answer to this is probably "undefined" depending on the OpenJPA configuration.

    My team solved this requirement by not allowing OpenJPA to handle the schema directly, but run sql update scripts at each deployment that needs a schema-change.