• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does a getter method in JPA need an underlying instance variable?

 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I'm unsure if a getter method in an entity bean has to have an underlying instance variable to be recognized as an property by the persistence manager. Or could it possibly be just a value deduced from some other data? I think it should be possible to provide getter methods without a directly corresponding instance variable but i couldn't find a clear statement to this problem.

Thanks for an answer!

Marco
 
Erik Bengtson
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marco, you don't need any instance variable...
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You sometimes will find that these are like formula fields, since the data that gets returned is basically calculated from other values that are in the class.

Mark
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers. However on second thoughts i reached the conclusion that it would be just stupid to persist something that can be calculated from other values anyway.

So i think in practice i would rather mark such a property @Transient than persisting it wouldn't i? I think storing it in the database would just create more redundancy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic