Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the easiest way to ignore a JPA field during persistence?

I'm essentially looking for a "@Ignore" type annotation with which I can stop a particular field from being persisted. How can this be achieved?

like image 483
m2o Avatar asked Aug 15 '09 13:08

m2o


People also ask

How do I ignore a field in JPA?

To ignore a field, annotate it with @Transient so it will not be mapped by hibernate.

How do you make a field non persistent?

@Transient annotation is used to ignore a field to not persist in database in JPA, where as transient key word used to ignore a field from serialization. The field annotated with @Transient still can be serialized, but the field declared with transient keyword not to be persisted and not to be serialized.

What annotation can exclude fields and properties of entity from mapping in JPA?

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.

How do you ignore a field in entity class to create a table?

Every non static non transient property (field or method depending on the access type) of an entity is considered persistent , unless you annotate it as @Transient . So you can use @Transient annotation on the property you do not wish to create a column for in database.


1 Answers

@Transient complies with your needs.

like image 98
cletus Avatar answered Sep 18 '22 22:09

cletus