This is the third question today that can be answered by giving a hint towards the formula option when defining a property, which leads to a computed property. That's a nice easy way for me to earn credits.
Concerning your methodological question. The downside of solution B doesn't only enter the field when doing computations on database fields. Data encapsulation even means that no one apart from the object owning the data should access a single field directly. With many fields, this seems overcautious, but if you have a legacy field in a strange format or semantics, it might become meaningful.
The situation is at least improved by using Hibernate's computed properties. Even if you don't express the computation in Java, but in SQL instead, you can get it into your class source (using XDoclet or Annotations), and, AFAIK, you can redefine the formula for each of your subclasses, if that's needed.
|