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

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


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

but then jackson will not serialize the field when converting to JSON.

If you need mix JPA with JSON(omit by JPA but still include in Jackson) use @JsonInclude :

@JsonInclude()@Transientprivate String token;

TIP:

You can also use JsonInclude.Include.NON_NULL and hide fields in JSON during deserialization when token == null:

@JsonInclude(JsonInclude.Include.NON_NULL)@Transientprivate String token;


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