What does @Transient annotation mean for methods?

So, I found out that the transient keyword in Java means that the entity is not saved and that the @Transient annotation in JPA means that the field is not saved in the database. But what does it mean when @Transient is applied to a method, not a variable?

This is where I found it in our code:

 @Transient public boolean getTabFoo() { if ((this.viewFoo1 != ACCESS_NONE) || (this.viewFoo2 != ACCESS_NONE) || (this.viewFoo3 != ACCESS_NONE) || (this.getViewFoo4() != ACCESS_NONE)) { return true; } return false; } 
+6
source share
2 answers

All JPA annotations at the field level can be placed either by field or by property, they determine the type of access for the object (that is, how the JPA provider will access the fields of this object - directly or using getters / setters).

The default access type is determined by the location of the @Id annotation, and it must be consistent across all fields of an object (or hierarchical inheritance of inherited objects) unless @Access explicitly redefined for some fields.

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

+6
source

Well, this is the correct getter method that JPA will by default consider bound to the entity property. If you do not want JPA to treat getter as a property, you apply the @Transient annotation to the method.

0
source

All Articles