Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will adding a column externally to a table mapped by JPA break normal functioning?

I'm new to JPA and I'm learning a lot about it. I recently deployed an application with EclipseLink as my JPA provider and it is running well.

Now there is a need to add an extra column to one of the mapped tables. This extra field is for reporting purposes and does not affect my application, so I really don't want to touch something that is working well. I will of course update my application in due time to include this field in my mappings but I don't want to do it just now.

This column addition will be done externally by the DBA directly to the tables. Will this addition break my application?

I believe that this should not happens since there is no change in the mapped fields and as far as JPA is concerned nothing has changed. JPA will not be aware of what was added so everything should work without breaking.

Please correct me if I'm wrong. Thanks.

like image 797
Karthic Raghupathi Avatar asked Jul 19 '12 14:07

Karthic Raghupathi


People also ask

Which JPA annotation can be used to map the class field to a DB column?

We can use the JPA @Lob annotation to map large fields to large database object types.

Is @column mandatory in JPA?

Let's start with the @Column annotation. It is an optional annotation that enables you to customize the mapping between the entity attribute and the database column.

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

Of-course if you use it only for querying purpose then it should be fine.

What will happen if @table is not specified while defining pojo?

If no @Table is defined the default values are used: the unqualified class name of the entity. For example if you have: @Entity public class MyTest{ ... Your table will have the name my_test in your database.


2 Answers

You can do it there's no reason it could break, JPA does not force you to map every column to a field in your entity. Except if the new column is mandatory (NOT NULL) and does not have a default value (on insert for example).

like image 137
Alex Avatar answered Oct 04 '22 01:10

Alex


Will this addition break my application?

No, it will not.

JPA allows you to map only the tables and fields you actually need.

like image 24
Jean Logeart Avatar answered Oct 04 '22 00:10

Jean Logeart