Can an entity class work without having a definition for all columns of the table

kjkszpj picture kjkszpj · Oct 31, 2013 · Viewed 8.2k times · Source

I implemented database querying for a table using jpa. I have added a new column in database for the table and completed my coding.

If after some time the deployment got reverted, consider I added a activeFlag column and it needs to be removed from my code later, will the previous version of the deployment work? i.e., it will have an entityClass for the table without the activeFlag but the data base will have it, and there will be no mapping defined to the activeFalg column in database in the generated entity class.

Will that be fine?

Answer

Nathan Hughes picture Nathan Hughes · Oct 31, 2013

If you have a table mapped to a JPA entity where there are columns that aren't getting mapped, those will be ignored by the JPA code. Having an unmapped column isn't going to break anything.