EN
Spring JPA - ignore entity field with @Transient
8
points
In this short article, we would like to show how to ignore some entiy fields in Spring JPA.
Quick solution:
Use
@Transient
annotation.
Practical example:
package com.example;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name = "users")
public class UserEntiy {
// some fields here ...
@Transient
private String ignoredField;
// some fields here ...
}
Note:
@Transient
causes the field is not mapped by Hibernate (will be not serialized by Jackson too).