title: Mapping calculated properties with JPA
body: <p>Is there a way to map a calculated property using JPA?</p>
  
  <p>Assuming I have an <code>Invoice</code> object with one or more <code>InvoiceLineItems</code> within it, I want to have a persistent calculated property on the <code>Invoice</code> class that gives me the total amount:</p>
  
  <pre><code>class Invoice {
      ...
  
      @Column(name = "TOTAL_AMOUNT")
      public BigDecimal getTotalAmount() {
          BigDecimal amount = BigDecimal.ZERO;
          for (InvoiceLineItem lineItem : lineItems) {
              amount = amount.add(lineItem.getTotalAmount());
          }
          return amount;
      }
  }
  </code></pre>
  
  <p>Now, I could create a protected no-op <code>setTotalAmount</code> method to make JPA happy, but I was wondering if there is a way to let JPA know that the mapping is one way only and to avoid creating a superfluous setter method.</p>
  
  <p>Thanks,
  Aleks</p>