Kumar Aditya
Kumar Aditya

Reputation: 229

Can a JPA entity have a field not mapped to a DB column

Is it possible for a JPA entity to have a field which is not mapped to any column in the data base table. Basically I need to store some additional data on my front end but I do not want to create an extra column in the table for this.

Upvotes: 16

Views: 17173

Answers (2)

Kumar Aditya
Kumar Aditya

Reputation: 229

Marking @Transient annotation solve this problem but it will work after restart host server(application/web).

Upvotes: 3

Maciej Kowalski
Maciej Kowalski

Reputation: 26522

Just mark the field or getter with @javax.persistence.Transient annotation.

The data stored there will not be persisted, nor the ddl generator, if you use any, will pick that one up as an additional column of the table.

Upvotes: 22

Related Questions