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.
Introduction. When persisting Java objects into database records using an Object-Relational Mapping (ORM) framework, we often want to ignore certain fields. If the framework is compliant with the Java Persistence API (JPA), we can add the @Transient annotation to these fields.
There are a number of different ways you can handle it but it really is situational. If your table without a key has a foreign key into another table that does have an id, you can use the @Embedded annotation.
To ignore a field, annotate it with @Transient so it will not be mapped by hibernate.
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.
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.
Marking @Transient annotation solve this problem but it will work after restart host server(application/web).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With