1

This is not really a issue but it is a sometimes annoying thing during my development. Let's say I have some entities (db is created according those entities, not otherwise) and I decided to add a column, drop a column or something and now I need to commit those changes to my DB.

What is the best way to do that? I sometimes have to restart Glassfish; sometimes deploying it is enough; sometimes I need to erase tables manually because restarting won't help. My strategy in persistence.xml is set to Create but other options didn't really help me.

Is there any standard approach for commiting changes from entities to database?

4

1 に答える 1

1

From what I know there is no standard way in JPA to alter tables automagically during development and still keep the data in the table. For some cases switching to CREATE-DROP will do the trick - but then you will loose the data in the table and pretty quickly need to write scripts to populate said table. As you said it is not a big issue for you and it might be good practice to go from CREATE-DROP to a method that works in multi-person projects. My/our way is to have a sql script file in the repo, and when I alter my entites I (manually) alter that script or add a new script (the latter if the table is already in production or the data in the table is either more than a few line of inserts or created by use and not easily reproducable). This way we work with constantly merged and runnable code. Other project-members wanting to run the current development branch against a (local?) db where the table is out-of-date just needs to execute the sql script.

于 2012-04-28T17:23:06.873 に答える