What does @Transient annotation mean for methods?

后端 未结 2 1333
予麋鹿
予麋鹿 2021-02-20 00:56

So I have learned that the transient keyword in Java means that an entity does not persist, and that the @Transient annotation in JPA means don\'t pers

相关标签:
2条回答
  • 2021-02-20 01:26

    All field-level JPA annotations can be placed either on fields or on properties, it determines access type of the entity (i.e. how JPA provider will access fields of that entity - directly or using getters/setters).

    Default access type is determined by placement of @Id annotation, and it should be consistent for all fields of the entity (or hiererchy of inherited entities), unless explicitly overriden by @Access for some fields.

    So, @Transient on getters has the same meaning as @Transient on fields - if default access type for your entity is property access, you need to annotate all getters that don't correspond to persistent properties with @Transient.

    0 讨论(0)
  • 2021-02-20 01:26

    Well it's a proper getter method, which JPA by default will assume is bound to an entity property. If you don't want JPA to treat a getter as a property, you apply the @Transient annotation to the method.

    0 讨论(0)
提交回复
热议问题