liveBook · Manning

@transient

As explained in Java Persistence with Spring Data and Hibernate epub

The JPA Transient annotation marks a persistent-class field or property that must not be stored in persistent data.

@Transient excludes a field or property from persistence while leaving it available at runtime. In JPA, place it on the field or getter according to the entity’s access strategy; field access is used when @Id is placed on fields. section 6.1.1 section 14.2

Computed entity property

An Item can persist initialPrice while calculating totalPriceIncludingTax at runtime. Marking totalPriceIncludingTax with @javax.persistence.Transient prevents a redundant database column. The Java transient keyword is an alternative when the field should also be excluded from Java serialization. section 6.1.1

Choose non-persistence for values that:

  • Are derived from other persistent properties and can be recalculated. section 6.1.1
  • Are sensitive, such as a clear-text password, and should not be stored for later disclosure. section 6.1.1 section 17.2
  • Have meaning only in a local environment, such as a local IP address. section 6.1.1

The same annotation name also appears in Spring Data MongoDB. There, @Transient marks a field that will not be persisted or examined by the persistence framework; a User password field uses it for this purpose. section 17.2

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains field or getter placement, access strategy, and the distinction from Java transient, but not provider internals.
Examples
Uses a computed price, a clear-text password, a local IP address, and a MongoDB User entity.
What you can do after
Apply it via JPA or Spring Data MongoDB to keep runtime-only fields out of stored data.
How it connects
Connects JPA persistence, Java serialization, entity access strategies, derived properties, and Spring Data MongoDB.

Also explained in

Compare how 2 books explain @transient →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.