File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Does a getter method in JPA need an underlying instance variable? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Does a getter method in JPA need an underlying instance variable?" Watch "Does a getter method in JPA need an underlying instance variable?" New topic
Author

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

Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1179
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

Joined: Dec 06, 2003
Posts: 90
Marco, you don't need any instance variable...
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16622

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1179
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.
 
 
subject: Does a getter method in JPA need an underlying instance variable?
 
Threads others viewed
spring
getters and setters provide abstraction or encapsulation ?
EL .(dot) operator
Encapsulation...
Command line arguments passed to main: how do I access them from other classes? ..
jQuery in Action, 2nd edition