@Transient Annotation in JPA
Fast recall
Quick revision
Core answer
Whether you understand the in-memory vs persisted boundary and the @Transient-vs-transient-keyword distinction
Confusing @Transient (persistence) with the transient keyword (serialization), or expecting @Transient fields to survive a reload
Give a concrete derived-field example and note you must recompute @Transient fields after loading
Interview-ready guide
Interview answer
A field marked @Transient is part of the Java object but not part of the JPA mapping. For example, an Invoice can expose a displayTotal calculated from its persisted line items without storing a separate display_total column. JPA ignores that field during INSERT, UPDATE, and hydration. That does not mean it must remain null: the class can calculate it in a getter, initialize it normally, or fill it in a @PostLoad callback. Use the Java transient keyword separately when the concern is Java serialization.
@Transient Annotation in JPA
Direct Answer
@Transient tells JPA not to map a field or property to the database. JPA does not read or write it. The value is not required to be null after loading: a field initializer, constructor, lifecycle callback, or application code can calculate it. Java's transient keyword is different; it controls Java serialization.
Common Mistakes & Pitfalls
@Transientvstransientkeyword — the annotation excludes from the database; the keyword excludes from serialization. Different concerns.- Expecting persistence —
@Transientfields reset to null/default on reload; they're never stored. - Forgetting to recompute — derived
@Transientfields stay null unless computed in a getter or after fetch. - Using it for real data — anything that must survive a restart belongs in a real column.
Check your understanding
Answer these without looking back at the article.
- What is the difference between @Transient and Java's transient keyword?
- How do you calculate a @Transient field value after loading?
- Does @Transient affect JSON serialization?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.