Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 490
kjkszpj Avatar asked Oct 31 '13 18:10

kjkszpj


People also ask

Can we create entity without id column?

An entity must always have a primary key; you cannot create an entity without a primary key (id).

Can we define entity class without primary key?

When you define an entity object, it must have a primary key or use a RowID attribute (based on the table's ROWID). To do so, you must create a new attribute while you are defining your entity object in the Entity Object Wizard.

How entity class is defined in JPA?

To transform this class into an entity add @Entity and @Id annotation in it. @Entity - This is a marker annotation which indicates that this class is an entity. This annotation must be placed on the class name. @Id - This annotation is placed on a specific field that holds the persistent identifying properties.


1 Answers

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.

like image 125
Nathan Hughes Avatar answered Sep 20 '22 12:09

Nathan Hughes