Search code examples
jpaspring-rooalter-table

Spring Roo - update a deployed entity


Suppose that using Spring Roo, I have created a web-app with a "User" entity storing user data. It has two string fields firstname and lastname.

I deploy this to production and Users get created and saved in DB.

I now would like to add a field, say dateOfBirth to the entity. This is easily done using Roo.

How is updating of the DB table in the background done? Can I just redeploy over the previous war and the DB gets automagically updated?

How / where can I define how the existing DB entries which lack the DOB are handled (eg. put in an "n/a" value).

Links to relevant docs are welcome.


Solution

  • The DDL generation strategy is configured in src/main/resources/META-INF/persistence.xml

    For hibernate, use the property hibernate.hbm2ddl.auto. This post describes the meaning of this property.

    For eclipselink, use the property eclipselink.ddl-generation. This link gives more information on configuring DDL generation in eclipselink.

    I think things are a bit more involved if you are using datanucleus or openjpa as your persistence provider.