注释接口 Transient


@Documented @Retention(RUNTIME) @Target(allowedTargets=PROPERTY) @Target(METHOD) public @interface Transient

Example-1: Transient property

If no argument of this annotation is not specified, the decorated property is a transient property, that means you can only get and set(by draft) it and ORM will ignore it

Otherwise, the decorated property is a complex calculation property that means you can add it into ObjectFetcher and jimmer will load it in query.

`@Transient` with argument means complex calculation means complex calculation property, You can also view Formula which can be used as simple calculation property

Example-1: Transient property ignored by ORM


 public class BookStore {

     ...omit other properties...

     @Transient
     String userData();

 }

Example-2: Complex calculation property whose return type is scalar type


 public class BookStore {

     ...omit other properties...

     @Id
     long id();

     @Transient(BookStoreAvgPriceResolver.class)
     BigDecimal avgPrice();
 }

 // If `TransientResolverProvider` of `SqlClient` is `SpringTransientResolverProvider`,
 // please decorate the resolver class by 'org.springframework.stereotype.Component'
 @Component
 class BookStoreAvgPriceResolver implements TransientResolver<Long, BigDecimal>{
     ...omit code...
 }

Example-3: Complex calculation property whose return type is entity type


 public class BookStore {

     ...omit other properties...

     @Id
     long id();

     @Transient(BookStoreMostPopularAuthorResolver.class)
     Author mostPopularAuthor();
 }

 // If `TransientResolverProvider` of `SqlClient` is `SpringTransientResolverProvider`,
 // please decorate the resolver class by 'org.springframework.stereotype.Component'
 @Component
 class BookStoreMostPopularAuthorResolver implements TransientResolver<Long, Long>{
     ...omit code...
 }

Example-4: Complex calculation property whose return type is list of entity type


 public class BookStore {

     ...omit other properties...

     @Id
     long id();

     @Transient(BookStoreNewestBooksResolver.class)
     List<Book> newestBooks();
 }

 // If `TransientResolverProvider` of `SqlClient` is `SpringTransientResolverProvider`,
 // please decorate the resolver class by 'org.springframework.stereotype.Component'
 @Component
 class BookStoreNewestBooksResolver implements TransientResolver<Long, List<Long>>{
     ...omit code...
 }
另请参阅:
  • 可选元素概要

    可选元素
    修饰符和类型
    可选元素
    说明
    In multi-module project, the resolver type may be declared in another module so that value() cannot be specified, please use this argument
     
  • 元素详细资料

    • value

      Class<?> value
      返回:
      A class implements `org.babyfish.jimmer.sql.TransientResolver` of jimmer-sql or `org.babyfish.jimmer.sql.kt.KTransientResolver` of jimmer-sql-kotlin.

      The first type argument of `TransientResolver` should the `ID` of declaring entity type

      • If the current calculation property returns simple type, the second type argument of `TransientResolver` should be return type of current property
      • If the current calculation property returns entity type, the second type argument of `TransientResolver` should be `ID` of target entity type
      • If the current calculation property returns a list whose element type is entity type, the second type argument of `TransientResolver` should be a list whose element type is `ID` of target entity type
      In multi-module project, the resolver type may be declared in another module so that `value` cannot be specified, please use ref()
      默认值:
      void.class
    • ref

      String ref
      In multi-module project, the resolver type may be declared in another module so that value() cannot be specified, please use this argument

      This argument can only be used with spring, it means the spring bean name of resolver object.

      返回:
      The spring bean name
      默认值:
      ""