@Transient는 Java Persistence API (JPA)에서 사용되는 애노테이션으로, 엔티티 클래스의 특정 필드가 데이터베이스 테이블에 매핑되지 않도록 지정
즉, 해당 필드는 데이터베이스와 상호작용하지 않으며, 영속성 컨텍스트(persistence context)에 포함되지 않음
@Transient로 선언된 필드는 데이터베이스에 저장되지 않으며, 쿼리 결과로 조회되지 않음@Transient는 JPA 표준 애노테이션@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private double price;
private double discount;
@Transient // 데이터베이스에 저장되지 않음
private double discountedPrice;
public double getDiscountedPrice() {
return price - discount; // 애플리케이션 내에서만 계산
}
}
discountedPrice는 데이터베이스 테이블에 저장되거나 조회되지 않음@Transient로 선언된 필드를 무시@Transient 필드는 데이터베이스와 매핑되지 않으므로, INSERT, UPDATE, SELECT 쿼리에 포함되지 않음JPA의 @Transient와 Spring의 @Transient(from org.springframework.data.annotation.Transient)는 다른 용도로 사용
@Transient:@Transient: